From 4421c8154d0e9fb258e022caae4c4fdd32aed2f1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 4 Mar 2024 10:11:47 -0300 Subject: [PATCH] Fix isLoading state initialization and add delay before refreshing --- .../components/parameterComponent/index.tsx | 1 - src/frontend/src/components/ui/refreshButton.tsx | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 942d62135..d71632ce5 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -69,7 +69,6 @@ export default function ParameterComponent({ const nodes = useFlowStore((state) => state.nodes); const edges = useFlowStore((state) => state.edges); const setNode = useFlowStore((state) => state.setNode); - const [isLoading, setIsLoading] = useState(false); const flow = currentFlow?.data?.nodes ?? null; diff --git a/src/frontend/src/components/ui/refreshButton.tsx b/src/frontend/src/components/ui/refreshButton.tsx index 7374686f2..3ac90be77 100644 --- a/src/frontend/src/components/ui/refreshButton.tsx +++ b/src/frontend/src/components/ui/refreshButton.tsx @@ -13,13 +13,20 @@ function RefreshButton({ }) { const [isLoading, setIsLoading] = useState(false); - const handleClick = () => { + const handleClick = async () => { setIsLoading(true); console.log("refreshing"); handleUpdateValues(name, data); - setInterval(() => { + try { + // Wait for at least 500 milliseconds + await new Promise((resolve) => setTimeout(resolve, 500)); + // Continue with the request + // If the request takes longer than 500 milliseconds, it will not wait an additional 500 milliseconds + } catch (error) { + console.error("Error occurred while waiting for refresh:", error); + } finally { setIsLoading(false); - }, 500); + } }; return (