Skip to content

Commit

Permalink
feat: added interval updates to production-list
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Apr 10, 2024
1 parent b476854 commit a2bc1fd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/landing-page/productions-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ const ProductionId = styled.div`

export const ProductionsList = () => {
const [productions, setProductions] = useState<TProduction[]>([]);
const [intervalLoad, setIntervalLoad] = useState<boolean>(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;
Expand Down Expand Up @@ -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 (
<ProductionListContainer>
Expand Down

0 comments on commit a2bc1fd

Please sign in to comment.