]> git.localhorst.tv Git - alttp.git/commitdiff
periodically refresh schedule
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 14:43:43 +0000 (15:43 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 14:43:43 +0000 (15:43 +0100)
resources/js/components/pages/Schedule.js

index 14d0891707e23a59da9b444c6c9cb5b115bd293d..5f82bfe3347d322d0178b86da342209a2d8129b1 100644 (file)
@@ -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]);