1 import axios from 'axios';
2 import moment from 'moment';
3 import React from 'react';
4 import { Alert, Container } from 'react-bootstrap';
5 import { Helmet } from 'react-helmet';
6 import { useTranslation } from 'react-i18next';
8 import CanonicalLinks from '../common/CanonicalLinks';
9 import ErrorBoundary from '../common/ErrorBoundary';
10 import Filter from '../episodes/Filter';
11 import List from '../episodes/List';
13 const Schedule = () => {
14 const [ahead, setAhead] = React.useState(14);
15 const [behind, setBehind] = React.useState(0);
16 const [episodes, setEpisodes] = React.useState([]);
17 const [filter, setFilter] = React.useState({});
19 const { t } = useTranslation();
21 React.useEffect(() => {
22 const savedFilter = localStorage.getItem('episodes.filter.schedule');
24 setFilter(JSON.parse(savedFilter));
26 setFilter(filter => filter ? {} : filter);
30 const updateFilter = React.useCallback(newFilter => {
31 localStorage.setItem('episodes.filter.schedule', JSON.stringify(newFilter));
35 const fetchEpisodes = React.useCallback((controller, ahead, behind, filter) => {
36 axios.get(`/api/episodes`, {
37 signal: controller.signal,
39 after: moment().startOf('day').subtract(behind, 'days').toISOString(),
40 before: moment().startOf('day').add(ahead + 1, 'days').toISOString(),
44 setEpisodes(response.data || []);
46 if (!axios.isCancel(e)) {
52 React.useEffect(() => {
53 const controller = new AbortController();
54 fetchEpisodes(controller, ahead, behind, filter);
55 const timer = setInterval(() => {
56 fetchEpisodes(controller, ahead, behind, filter);
62 }, [ahead, behind, fetchEpisodes, filter]);
66 <title>{t('schedule.heading')}</title>
67 <meta name="description" content={t('schedule.description')} />
69 <CanonicalLinks base="/schedule" />
70 <div className="d-flex align-items-start justify-content-between">
71 <h1>{t('schedule.heading')}</h1>
72 <div className="mt-5">
73 <Filter filter={filter} setFilter={updateFilter} />
78 <List episodes={episodes} />
80 <Alert variant="info">
88 export default Schedule;