From 7c1db464de8560af8f72228fc311c34f38c1134d Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 9 Aug 2023 13:07:27 +0200 Subject: [PATCH] more links --- app/Models/Episode.php | 1 - resources/js/components/episodes/Crew.js | 56 +++++++++++++++++++++++- resources/js/components/episodes/Item.js | 27 ++++++------ resources/js/helpers/Episode.js | 44 +++++++++++++++++++ resources/js/i18n/de.js | 1 + resources/js/i18n/en.js | 1 + 6 files changed, 113 insertions(+), 17 deletions(-) diff --git a/app/Models/Episode.php b/app/Models/Episode.php index 1c16f7f..7d3175c 100644 --- a/app/Models/Episode.php +++ b/app/Models/Episode.php @@ -39,7 +39,6 @@ class Episode extends Model protected $hidden = [ 'created_at', - 'ext_id', 'updated_at', ]; diff --git a/resources/js/components/episodes/Crew.js b/resources/js/components/episodes/Crew.js index 76a38a6..e645edb 100644 --- a/resources/js/components/episodes/Crew.js +++ b/resources/js/components/episodes/Crew.js @@ -6,6 +6,12 @@ import { useTranslation } from 'react-i18next'; import CrewMember from './CrewMember'; import Icon from '../common/Icon'; import { compareCrew } from '../../helpers/Crew'; +import { + getSGLanguages, + getSGSignupLink, + hasPassed, + hasSGRestream, +} from '../../helpers/Episode'; import { canApplyForEpisode } from '../../helpers/permissions'; import { withUser } from '../../helpers/UserContext'; @@ -22,8 +28,26 @@ const Crew = ({ episode, onApply, user }) => { episode.crew.filter(c => c.role === 'setup').sort(compareCrew) , [episode]); + const sgLanguages = React.useMemo(() => + getSGLanguages(episode) + , [episode]); + + const showCommentators = React.useMemo(() => + commentators.length || (!hasPassed(episode) && ( + canApplyForEpisode(user, episode, 'commentary') || + hasSGRestream(episode) + )) + , [commentators, episode, user]); + + const showTracker = React.useMemo(() => + trackers.length || (!hasPassed(episode) && ( + canApplyForEpisode(user, episode, 'tracking') || + hasSGRestream(episode) + )) + , [episode, trackers, user]); + return - {commentators.length || canApplyForEpisode(user, episode, 'commentary') ? + {showCommentators ?
@@ -42,9 +66,23 @@ const Crew = ({ episode, onApply, user }) => {
: null} + {hasSGRestream(episode) ? +
+ {sgLanguages.map(lang => + + )} +
+ : null} : null} - {trackers.length || canApplyForEpisode(user, episode, 'tracking') ? + {showTracker ?
@@ -63,6 +101,20 @@ const Crew = ({ episode, onApply, user }) => {
: null} + {hasSGRestream(episode) ? +
+ {sgLanguages.map(lang => + + )} +
+ : null} : null} {techies.length ? diff --git a/resources/js/components/episodes/Item.js b/resources/js/components/episodes/Item.js index d7c4bab..03cb6fe 100644 --- a/resources/js/components/episodes/Item.js +++ b/resources/js/components/episodes/Item.js @@ -1,4 +1,3 @@ -import moment from 'moment'; import PropTypes from 'prop-types'; import React from 'react'; import { Button } from 'react-bootstrap'; @@ -10,17 +9,10 @@ import Crew from './Crew'; import MultiLink from './MultiLink'; import Players from './Players'; import Icon from '../common/Icon'; +import { hasPassed, hasSGRestream, isActive } from '../../helpers/Episode'; import { canApplyForEpisode, canRestreamEpisode } from '../../helpers/permissions'; import { withUser } from '../../helpers/UserContext'; -const isActive = episode => { - if (!episode.start) return false; - const now = moment(); - const start = moment(episode.start).subtract(10, 'minutes'); - const end = moment(episode.start).add(episode.estimate, 'seconds'); - return start.isBefore(now) && end.isAfter(now); -}; - const Item = ({ episode, onAddRestream, onApply, onEditRestream, user }) => { const { t } = useTranslation(); @@ -94,18 +86,24 @@ const Item = ({ episode, onAddRestream, onApply, onEditRestream, user }) => { {hasPlayers ? : null} - {(episode.crew && episode.crew.length) + {(episode.crew && episode.crew.length) || (!hasPassed(episode) && ( + hasSGRestream(episode) || canApplyForEpisode(user, episode, 'commentary') - || canApplyForEpisode(user, episode, 'tracking') ? + || canApplyForEpisode(user, episode, 'tracking') + )) ?
: null} {episode.event ?
- - {episode.event.title} - + {episode.event.description_id ? + + {episode.event.title} + + : + episode.event.title + }
: null} @@ -121,6 +119,7 @@ Item.propTypes = { })), event: PropTypes.shape({ corner: PropTypes.string, + description_id: PropTypes.number, name: PropTypes.string, title: PropTypes.string, }), diff --git a/resources/js/helpers/Episode.js b/resources/js/helpers/Episode.js index 60c1a7b..696d39a 100644 --- a/resources/js/helpers/Episode.js +++ b/resources/js/helpers/Episode.js @@ -1,3 +1,5 @@ +import moment from 'moment'; + export const acceptsComms = episode => { if (!episode || !episode.channels) return false; return !!episode.channels.find(c => c.pivot && c.pivot.accept_comms); @@ -14,6 +16,48 @@ export const acceptsCrew = episode => { c.pivot && (c.pivot.accept_comms || c.pivot.accept_tracker)); }; +export const getSGLanguages = episode => { + if (!episode || !episode.channels) return []; + const sgChannels = episode.channels.filter( + c => c.stream_link && c.stream_link.startsWith('https://twitch.tv/speedgaming'), + ); + const langs = []; + sgChannels.forEach(channel => { + if (!channel.languages) return; + channel.languages.forEach(lang => { + if (!langs.includes(lang)) { + langs.push(lang); + } + }); + }); + return langs; +}; + +export const getSGSignupLink = (episode, lang, role) => + `https://speedgaming.org/${lang}/${role}/signup/${episode.ext_id.substr(3)}/`; + +export const hasPassed = episode => { + if (!episode || !episode.start) return false; + const now = moment(); + const end = moment(episode.start).add(episode.estimate, 'seconds'); + return end.isBefore(now); +}; + +export const hasSGRestream = episode => { + if (!episode || !episode.channels) return false; + return !!episode.channels.find( + c => c.stream_link && c.stream_link.startsWith('https://twitch.tv/speedgaming'), + ); +}; + +export const isActive = episode => { + if (!episode || !episode.start) return false; + const now = moment(); + const start = moment(episode.start).subtract(10, 'minutes'); + const end = moment(episode.start).add(episode.estimate, 'seconds'); + return start.isBefore(now) && end.isAfter(now); +}; + export const isEventSelected = (filter, event) => { return (filter.event || []).includes(event.id); }; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 28848e6..e55885f 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -123,6 +123,7 @@ export default { title: 'Restream', }, setup: 'Setup', + sgSignUp: 'SG Anmeldung', startTime: '{{ date, LL LT }} Uhr', tracking: 'Tracking', }, diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 4f4038a..52c9031 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -123,6 +123,7 @@ export default { title: 'Restream', }, setup: 'Setup', + sgSignUp: 'SG Signup', startTime: '{{ date, LL LT }}', tracking: 'Tracking', }, -- 2.39.2