]> git.localhorst.tv Git - alttp.git/commitdiff
add multilink for episodes without channel
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 20:52:07 +0000 (21:52 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 20:52:07 +0000 (21:52 +0100)
resources/js/components/episodes/Item.js
resources/js/components/episodes/MultiLink.js [new file with mode: 0644]

index 2078c6dc6573bb74f554032ae67a3fdc0323cd3d..5c6982972a6dbd57ca176bdfe0b296abb889d7ba 100644 (file)
@@ -5,13 +5,14 @@ import { useTranslation } from 'react-i18next';
 
 import Channels from './Channels';
 import Crew from './Crew';
+import MultiLink from './MultiLink';
 import Players from './Players';
 
 const isActive = episode => {
        if (!episode.start) return false;
        const now = moment();
-       const start = moment(episode.start);
-       const end = moment(start).add(episode.estimate, 'seconds');
+       const start = moment(episode.start).subtract(10, 'minutes');
+       const end = moment(episode.start).add(episode.estimate, 'seconds');
        return start.isBefore(now) && end.isAfter(now);
 };
 
@@ -31,6 +32,9 @@ const Item = ({ episode }) => {
                classNames.push('is-active');
        }
 
+       const hasChannels = episode.channels && episode.channels.length;
+       const hasPlayers = episode.players && episode.players.length;
+
        return <div className={classNames.join(' ')}>
                <div className="episode-start me-3 fs-4 text-end">
                        {t('schedule.startTime', { date: new Date(episode.start) })}
@@ -50,12 +54,15 @@ const Item = ({ episode }) => {
                                        : null}
                                </div>
                                <div>
-                                       {episode.channels ?
+                                       {hasChannels ?
                                                <Channels channels={episode.channels} />
                                        : null}
+                                       {!hasChannels && hasPlayers ?
+                                               <MultiLink players={episode.players} />
+                                       : null}
                                </div>
                        </div>
-                       {episode.players && episode.players.length ?
+                       {hasPlayers ?
                                <Players players={episode.players} />
                        : null}
                        {episode.crew && episode.crew.length ?
diff --git a/resources/js/components/episodes/MultiLink.js b/resources/js/components/episodes/MultiLink.js
new file mode 100644 (file)
index 0000000..b66d2fe
--- /dev/null
@@ -0,0 +1,35 @@
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Button } from 'react-bootstrap';
+
+import Icon from '../common/Icon';
+import { getStreamLink } from '../../helpers/Crew';
+
+const MultiLink = ({ players }) => {
+       const streams = players.map(getStreamLink);
+       const names = streams.map(s => s.split('/').pop());
+       const url = `https://multitwitch.tv/${names.join('/')}`;
+
+       return <div className="episode-channel">
+               <Button
+                       href={url}
+                       rel="noreferer"
+                       target="_blank"
+                       title="MultiTwitch"
+                       variant="outline-twitch"
+               >
+                       <Icon.STREAM />
+                       {' MultiTwitch'}
+               </Button>
+       </div>;
+};
+
+MultiLink.propTypes = {
+       players: PropTypes.arrayOf(PropTypes.shape({
+               short_name: PropTypes.string,
+               stream_link: PropTypes.string,
+               title: PropTypes.string,
+       })),
+};
+
+export default MultiLink;