From: Daniel Karbach Date: Thu, 10 Aug 2023 08:21:49 +0000 (+0200) Subject: reduce event timeframe X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d4a1005e2c41440a7dba3f238a64e509a2fe6f6f;p=alttp.git reduce event timeframe --- diff --git a/resources/js/components/pages/Schedule.js b/resources/js/components/pages/Schedule.js index cac23e7..4c342df 100644 --- a/resources/js/components/pages/Schedule.js +++ b/resources/js/components/pages/Schedule.js @@ -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(); };