]> git.localhorst.tv Git - alttp.git/commitdiff
fix ongoing events filter
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 5 Sep 2024 07:57:19 +0000 (09:57 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 5 Sep 2024 07:57:19 +0000 (09:57 +0200)
resources/js/helpers/Event.js
resources/js/pages/Events.js

index f928be1def6cd7321fbea0bde747d765929716f9..c39daaab01ceff30f3d494479a79177ff6c56292 100644 (file)
@@ -3,3 +3,27 @@ import moment from 'moment';
 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;
+};
index d7ecde26ef5a5cdec5eb160210704a58805ae5a4..b65652e23bd0541645c14a3be06af32a8227b558 100644 (file)
@@ -9,6 +9,7 @@ import ErrorBoundary from '../components/common/ErrorBoundary';
 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();
@@ -56,13 +57,13 @@ export const Component = () => {
        }, [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) {