From 2fbec6f21ff2c8a737f4624fdedf888f207e9256 Mon Sep 17 00:00:00 2001 From: utin-francis-peter Date: Wed, 19 Jun 2024 23:39:16 +0100 Subject: [PATCH] chore: added cleanup fxn for TrainingProgress timeout fxn --- frontend/src/upload/Upload.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index 6437acc..242070a 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -94,8 +94,10 @@ export default function Upload({ function TrainingProgress() { const dispatch = useDispatch(); useEffect(() => { - (progress?.percentage ?? 0) < 100 && - setTimeout(() => { + let timeoutID: number | undefined; + + if ((progress?.percentage ?? 0) < 100) { + timeoutID = setTimeout(() => { const apiHost = import.meta.env.VITE_API_HOST; fetch(`${apiHost}/api/task_status?task_id=${progress?.taskId}`) .then((data) => data.json()) @@ -133,6 +135,14 @@ export default function Upload({ } }); }, 5000); + } + + // cleanup + return () => { + if (timeoutID !== undefined) { + clearTimeout(timeoutID); + } + }; }, [progress, dispatch]); return (