From ce8c274721928aa35a07beafb1f6ae1ce75e7d4d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 4 Mar 2024 10:31:33 -0300 Subject: [PATCH] Refactor RefreshButton component to handle disabled state and loading state --- .../src/components/ui/refreshButton.tsx | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/components/ui/refreshButton.tsx b/src/frontend/src/components/ui/refreshButton.tsx index 3ac90be77..5ff581faf 100644 --- a/src/frontend/src/components/ui/refreshButton.tsx +++ b/src/frontend/src/components/ui/refreshButton.tsx @@ -3,10 +3,12 @@ import IconComponent from "../../components/genericIconComponent"; import { NodeDataType } from "../../types/flow"; import { cn } from "../../utils/utils"; function RefreshButton({ + disabled, name, data, handleUpdateValues, }: { + disabled: boolean; name: string; data: NodeDataType; handleUpdateValues: (name: string, data: NodeDataType) => void; @@ -14,6 +16,7 @@ function RefreshButton({ const [isLoading, setIsLoading] = useState(false); const handleClick = async () => { + if (disabled) return; setIsLoading(true); console.log("refreshing"); handleUpdateValues(name, data); @@ -28,15 +31,23 @@ function RefreshButton({ setIsLoading(false); } }; + const className = cn( + "extra-side-bar-buttons ml-2 mt-1 w-1/6", + disabled ? "cursor-not-allowed" : "cursor-pointer" + ); + // icon class name should take into account the disabled state and the loading state + const disabledIconTextClass = disabled ? "text-muted-foreground" : ""; + const iconClassName = cn( + "h-4 w-4", + isLoading ? "animate-spin" : "animate-wiggle", + disabledIconTextClass + ); return ( - );