]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Episode.js
save tracker config
[alttp.git] / resources / js / helpers / Episode.js
1 import moment from 'moment';
2
3 export const acceptsComms = episode => {
4         if (!episode || !episode.channels) return false;
5         return !!episode.channels.find(c => c.pivot && c.pivot.accept_comms);
6 };
7
8 export const acceptsTrackers = episode => {
9         if (!episode || !episode.channels) return false;
10         return !!episode.channels.find(c => c.pivot && c.pivot.accept_tracker);
11 };
12
13 export const acceptsCrew = episode => {
14         if (!episode || !episode.channels) return false;
15         return !!episode.channels.find(c =>
16                 c.pivot && (c.pivot.accept_comms || c.pivot.accept_tracker));
17 };
18
19 export const getSGLanguages = episode => {
20         if (!episode || !episode.channels) return [];
21         const sgChannels = episode.channels.filter(
22                 c => c.stream_link && c.stream_link.startsWith('https://twitch.tv/speedgaming'),
23         );
24         const langs = [];
25         sgChannels.forEach(channel => {
26                 if (!channel.languages) return;
27                 channel.languages.forEach(lang => {
28                         if (!langs.includes(lang)) {
29                                 langs.push(lang);
30                         }
31                 });
32         });
33         return langs;
34 };
35
36 export const getSGSignupLink = (episode, lang, role) =>
37         `https://speedgaming.org/${lang}/${role}/signup/${episode.ext_id.substr(3)}/`;
38
39 export const hasPassed = episode => {
40         if (!episode || !episode.start) return false;
41         const now = moment();
42         const end = moment(episode.start).add(episode.estimate, 'seconds');
43         return end.isBefore(now);
44 };
45
46 export const hasSGRestream = episode => {
47         if (!episode || !episode.channels) return false;
48         return !!episode.channels.find(
49                 c => c.stream_link && c.stream_link.startsWith('https://twitch.tv/speedgaming'),
50         );
51 };
52
53 export const isActive = episode => {
54         if (!episode || !episode.start) return false;
55         const now = moment();
56         const start = moment(episode.start).subtract(10, 'minutes');
57         const end = moment(episode.start).add(episode.estimate, 'seconds');
58         return start.isBefore(now) && end.isAfter(now);
59 };
60
61 export const isEventSelected = (filter, event) => {
62         return (filter.event || []).includes(event.id);
63 };
64
65 export const toggleEventFilter = (events, filter, event) => {
66         const eventFilter = filter.event || [];
67         if (eventFilter.includes(event.id)) {
68                 return {
69                         ...filter,
70                         event: eventFilter.filter(id => id !== event.id && events.find(e => e.id === id)),
71                 };
72         }
73         return {
74                 ...filter,
75                 event: [...eventFilter, event.id],
76         };
77 };