From c3078124fff7a96ad1d15e591780c00e3ebf5c3a Mon Sep 17 00:00:00 2001 From: Shaun Orssaud Date: Mon, 1 Jan 2024 16:58:16 +0900 Subject: [PATCH] UPD upload now updates periodically --- .../src/pages/data/tabs/upload/UploadTab.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/data/tabs/upload/UploadTab.tsx b/frontend/src/pages/data/tabs/upload/UploadTab.tsx index 5da8abf..b7f4e1a 100644 --- a/frontend/src/pages/data/tabs/upload/UploadTab.tsx +++ b/frontend/src/pages/data/tabs/upload/UploadTab.tsx @@ -32,10 +32,37 @@ function UploadTab() { }); } useEffect(() => { - setUploads([]); + const fetchData = () => { + fetch(`/api/codex/v1/data`, { + headers: { + Authorization: nodeInfo.auth ? "Basic " + btoa(nodeInfo.auth) : "", + }, + }) + .then((response) => response.json()) + .then((data) => { + setUploads(data); + setIsLoading(false); + }) + .catch((error) => { + console.error("Error fetching data: ", error); + setIsLoading(false); + }); + }; + + const fetchDataInterval = setInterval(() => { + // Fetch data at regular intervals (every 5 seconds) + setIsLoading(true); + fetchData(); + }, 5000); // 5 seconds in milliseconds + + // Fetch data immediately when the component mounts setIsLoading(true); - // Fetch purchase IDs - getDatas(); + fetchData(); + + return () => { + // Clean up interval on component unmount + clearInterval(fetchDataInterval); + }; }, []); const onDrop = useCallback(