]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/Episode.js
more links
[alttp.git] / resources / js / helpers / Episode.js
index 60c1a7b9f77976e6c640aefbebeec644a5538c26..696d39a811385f9a7ab357af777ea84377b1da53 100644 (file)
@@ -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);
 };