1 import axios from 'axios';
2 import moment from 'moment';
3 import React from 'react';
4 import { 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 List from '../episodes/List';
12 const Schedule = () => {
13 const [ahead, setAhead] = React.useState(6);
14 const [behind, setBehind] = React.useState(0);
15 const [episodes, setEpisodes] = React.useState([]);
17 const { t } = useTranslation();
19 const fetchEpisodes = React.useCallback((controller, ahead, behind) => {
20 axios.get(`/api/episodes`, {
21 signal: controller.signal,
23 after: moment().startOf('day').subtract(behind, 'days').toISOString(),
24 before: moment().startOf('day').add(ahead + 1, 'days').toISOString(),
27 setEpisodes(response.data || []);
29 if (!axios.isCancel(e)) {
35 React.useEffect(() => {
36 const controller = new AbortController();
37 fetchEpisodes(controller, ahead, behind);
38 const timer = setInterval(() => {
39 fetchEpisodes(controller, ahead, behind);
49 <title>{t('schedule.heading')}</title>
50 <meta name="description" content={t('schedule.description')} />
52 <CanonicalLinks base="/schedule" />
53 <h1>{t('schedule.heading')}</h1>
55 <List episodes={episodes} />
60 export default Schedule;