X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Fpages%2FSchedule.js;h=cac23e7e66d19e5cc39534db61a528ef6a50349f;hb=a24b514e92a0d5fca7a6c99b6414aa4814065a7d;hp=ffbb69ef611f8deffaeb39ae09af27d0483e5c97;hpb=33157cf7893e1faf8006f4296eb99dd7adf5bc37;p=alttp.git
diff --git a/resources/js/components/pages/Schedule.js b/resources/js/components/pages/Schedule.js
index ffbb69e..cac23e7 100644
--- a/resources/js/components/pages/Schedule.js
+++ b/resources/js/components/pages/Schedule.js
@@ -14,6 +14,7 @@ import ApplyDialog from '../episodes/ApplyDialog';
import Filter from '../episodes/Filter';
import List from '../episodes/List';
import RestreamDialog from '../episodes/RestreamDialog';
+import { toggleEventFilter } from '../../helpers/Episode';
import { withUser } from '../../helpers/UserContext';
const Schedule = ({ user }) => {
@@ -21,6 +22,7 @@ const Schedule = ({ user }) => {
const [applyAs, setApplyAs] = React.useState('commentary');
const [behind] = React.useState(0);
const [episodes, setEpisodes] = React.useState([]);
+ const [events, setEvents] = React.useState([]);
const [filter, setFilter] = React.useState({});
const [restreamChannel, setRestreamChannel] = React.useState(null);
const [restreamEpisode, setRestreamEpisode] = React.useState(null);
@@ -39,17 +41,46 @@ const Schedule = ({ user }) => {
}
}, []);
+ React.useEffect(() => {
+ const controller = new AbortController();
+ axios.get(`/api/events`, {
+ signal: controller.signal,
+ params: {
+ after: moment().startOf('day').subtract(7, 'days').toISOString(),
+ before: moment().startOf('day').add(8, 'days').toISOString(),
+ },
+ }).then(response => {
+ const newEvents = (response.data || []).sort(
+ (a, b) => (a.short || a.title).localeCompare(b.short || b.title)
+ );
+ setEvents(newEvents);
+ }).catch(e => {
+ if (!axios.isCancel(e)) {
+ console.error(e);
+ }
+ });
+ return () => {
+ controller.abort();
+ };
+ }, []);
+
const updateFilter = React.useCallback(newFilter => {
localStorage.setItem('episodes.filter.schedule', JSON.stringify(newFilter));
setFilter(newFilter);
}, []);
+ const invertFilter = React.useCallback(() => {
+ updateFilter(events.reduce((newFilter, event) => {
+ return toggleEventFilter(events, newFilter, event);
+ }, filter));
+ }, [events, filter]);
+
const fetchEpisodes = React.useCallback((controller, ahead, behind, filter) => {
axios.get(`/api/episodes`, {
signal: controller.signal,
params: {
- after: moment().startOf('day').subtract(behind, 'days').toISOString(),
- before: moment().startOf('day').add(ahead + 1, 'days').toISOString(),
+ after: moment().subtract(8, 'hours').subtract(behind, 'days').toISOString(),
+ before: moment().add(16, 'hours').add(ahead, 'days').toISOString(),
...filter,
},
}).then(response => {
@@ -231,17 +262,28 @@ const Schedule = ({ user }) => {