]> git.localhorst.tv Git - alttp.git/commitdiff
reduce event timeframe
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 10 Aug 2023 08:21:49 +0000 (10:21 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 10 Aug 2023 08:21:49 +0000 (10:21 +0200)
resources/js/components/pages/Schedule.js

index cac23e7e66d19e5cc39534db61a528ef6a50349f..4c342df70a46ffce2b4ff9d62e89c732272c2d2e 100644 (file)
@@ -41,12 +41,11 @@ const Schedule = ({ user }) => {
                }
        }, []);
 
-       React.useEffect(() => {
-               const controller = new AbortController();
+       const fetchEvents = React.useCallback((controller) => {
                axios.get(`/api/events`, {
                        signal: controller.signal,
                        params: {
-                               after: moment().startOf('day').subtract(7, 'days').toISOString(),
+                               after: moment().startOf('day').subtract(1, 'days').toISOString(),
                                before: moment().startOf('day').add(8, 'days').toISOString(),
                        },
                }).then(response => {
@@ -59,6 +58,15 @@ const Schedule = ({ user }) => {
                                console.error(e);
                        }
                });
+       });
+
+       React.useEffect(() => {
+               const controller = new AbortController();
+               fetchEvents(controller);
+               const timer = setInterval(() => {
+                       fetchEvents(controller);
+                       clearInterval(timer);
+               }, 15 * 60 * 1000);
                return () => {
                        controller.abort();
                };