From: Daniel Karbach Date: Mon, 20 Feb 2023 14:43:43 +0000 (+0100) Subject: periodically refresh schedule X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=fb9c7a3524a5fc879bb062b343ec2f8fc3817f42;p=alttp.git periodically refresh schedule --- 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]);