From a2bc1fd35ab73fa34870aae52fe52e5621ed5ceb Mon Sep 17 00:00:00 2001 From: malmen237 Date: Wed, 10 Apr 2024 09:51:01 +0200 Subject: [PATCH] feat: added interval updates to production-list --- .../landing-page/productions-list.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/landing-page/productions-list.tsx b/src/components/landing-page/productions-list.tsx index 3096786f..46523faa 100644 --- a/src/components/landing-page/productions-list.tsx +++ b/src/components/landing-page/productions-list.tsx @@ -33,13 +33,16 @@ const ProductionId = styled.div` export const ProductionsList = () => { const [productions, setProductions] = useState([]); + const [intervalLoad, setIntervalLoad] = useState(false); const [{ reloadProductionList }, dispatch] = useGlobalState(); // TODO extract to separate hook file useEffect(() => { let aborted = false; - if (reloadProductionList) { + // TODO handle so future load-component isn't shown on every update + if (reloadProductionList || intervalLoad) { + setIntervalLoad(false); API.listProductions() .then((result) => { if (aborted) return; @@ -73,10 +76,21 @@ export const ProductionsList = () => { // TODO handle error/retry }); } + return () => { aborted = true; }; - }, [dispatch, reloadProductionList]); + }, [dispatch, reloadProductionList, intervalLoad]); + + useEffect(() => { + const interval = window.setInterval(() => { + setIntervalLoad(true); + }, 10000); + + return () => { + window.clearInterval(interval); + }; + }, []); return (