export const getLink = event => `/events/${event.name}`;
export const hasConcluded = event => event && event.end && moment(event.end).isBefore(moment());
+
+export const isEvergreen = event => event && !event.start && !event.end;
+
+export const isOngoing = event => event &&
+ event.start && (!event.end || moment().isBefore(event.end));
+
+export const compareStart = (a, b) => {
+ if (a && a.start) {
+ if (b && b.start) {
+ if (moment(a.start).isBefore(moment(b.start))) {
+ return -1;
+ }
+ if (moment(b.start).isBefore(moment(a.start))) {
+ return 1;
+ }
+ return 0;
+ }
+ return 1;
+ }
+ if (b && b.start) {
+ return -1;
+ }
+ return 0;
+};
import ErrorMessage from '../components/common/ErrorMessage';
import Loading from '../components/common/Loading';
import List from '../components/events/List';
+import { compareStart, hasConcluded, isEvergreen, isOngoing } from '../helpers/Event';
export const Component = () => {
const { t } = useTranslation();
}, [fetchEvents]);
const evergreen = React.useMemo(() =>
- events.filter(event => !event.start)
+ events.filter(isEvergreen)
, [events]);
const ongoing = React.useMemo(() =>
- events.filter(event => event.start && !event.end)
+ events.filter(isOngoing).sort((a, b) => compareStart(a, b) * -1)
, [events]);
const past = React.useMemo(() =>
- events.filter(event => event.end)
+ events.filter(hasConcluded)
, [events]);
if (loading) {