X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fpages%2FSchedule.js;h=5f82bfe3347d322d0178b86da342209a2d8129b1;hb=fb9c7a3524a5fc879bb062b343ec2f8fc3817f42;hp=14d0891707e23a59da9b444c6c9cb5b115bd293d;hpb=35dca1d496a5298daad2fc5f926a9fe400f68dce;p=alttp.git 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]);