1 import axios from 'axios';
2 import React from 'react';
3 import { Container } from 'react-bootstrap';
4 import { Helmet } from 'react-helmet';
5 import { useTranslation } from 'react-i18next';
7 import CanonicalLinks from '../components/common/CanonicalLinks';
8 import ErrorBoundary from '../components/common/ErrorBoundary';
9 import ErrorMessage from '../components/common/ErrorMessage';
10 import Loading from '../components/common/Loading';
11 import List from '../components/events/List';
13 export const Component = () => {
14 const { t } = useTranslation();
16 const [error, setError] = React.useState(null);
17 const [loading, setLoading] = React.useState(true);
18 const [events, setEvents] = React.useState([]);
20 const fetchEvents = React.useCallback(async (controller) => {
23 with: ['description'],
26 const response = await axios.get(`/api/events`, {
27 signal: controller.signal,
30 return response.data || [];
32 if (!axios.isCancel(error)) {
39 React.useEffect(() => {
40 const controller = new AbortController();
42 fetchEvents(controller)
58 const evergreen = React.useMemo(() =>
59 events.filter(event => !event.start)
61 const ongoing = React.useMemo(() =>
62 events.filter(event => event.start && !event.end)
64 const past = React.useMemo(() =>
65 events.filter(event => event.end)
73 return <ErrorMessage error={error} />;
76 return <ErrorBoundary>
82 <CanonicalLinks base={`/events`} />
84 <h1>{t('events.ongoing')}</h1>
85 <List events={ongoing} />
86 <h1>{t('events.evergreen')}</h1>
87 <List events={evergreen} />
88 <h1>{t('events.past')}</h1>
89 <List events={past} />