Fix isLoading state initialization and add delay before refreshing

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-04 10:11:47 -03:00
commit 4421c8154d
2 changed files with 10 additions and 4 deletions

View file

@ -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;

View file

@ -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 (