From fb9c7a3524a5fc879bb062b343ec2f8fc3817f42 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 20 Feb 2023 15:43:43 +0100 Subject: [PATCH 1/1] periodically refresh schedule --- resources/js/components/pages/Schedule.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/js/components/pages/Schedule.js b/resources/js/components/pages/Schedule.js index 14d0891..5f82bfe 100644 --- a/resources/js/components/pages/Schedule.js +++ b/resources/js/components/pages/Schedule.js @@ -16,8 +16,7 @@ const Schedule = () => { const { t } = useTranslation(); - React.useEffect(() => { - const controller = new AbortController(); + const fetchEpisodes = React.useCallback((controller, ahead, behind) => { axios.get(`/api/episodes`, { signal: controller.signal, params: { @@ -31,8 +30,17 @@ const Schedule = () => { console.error(e); } }); + }, [setEpisodes]); + + React.useEffect(() => { + const controller = new AbortController(); + fetchEpisodes(controller, ahead, behind); + const timer = setInterval(() => { + fetchEpisodes(controller, ahead, behind); + }, 5 * 60 * 1000); return () => { controller.abort(); + clearInterval(timer); }; }, [ahead, behind]); -- 2.39.2