diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index a44c6e299..8b22daabb 100644 --- a/client/src/components/Sidebar.tsx +++ b/client/src/components/Sidebar.tsx @@ -103,8 +103,30 @@ const Sidebar = ({ const [shownEnvVars, setShownEnvVars] = useState>(new Set()); const [copiedServerEntry, setCopiedServerEntry] = useState(false); const [copiedServerFile, setCopiedServerFile] = useState(false); + const [isConnecting, setIsConnecting] = useState(false); const { toast } = useToast(); + // Wrapper for onConnect that manages loading state + const handleConnect = useCallback(async () => { + try { + setIsConnecting(true); + await onConnect(); + } finally { + setIsConnecting(false); + } + }, [onConnect]); + + // Wrapper for restart that manages loading state + const handleRestart = useCallback(async () => { + try { + setIsConnecting(true); + onDisconnect(); + await onConnect(); + } finally { + setIsConnecting(false); + } + }, [onConnect, onDisconnect]); + // Reusable error reporter for copy actions const reportError = useCallback( (error: unknown) => { @@ -672,10 +694,8 @@ const Sidebar = ({
)} {connectionStatus !== "connected" && ( - diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsx index 8e435c3c8..0a238681a 100644 --- a/client/src/components/ui/button.tsx +++ b/client/src/components/ui/button.tsx @@ -38,17 +38,77 @@ export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; + loading?: boolean; + loadingText?: string; } +const LoadingSpinner = () => ( + + + + +); + const Button = React.forwardRef( - ({ className, variant, size, asChild = false, ...props }, ref) => { + ( + { + className, + variant, + size, + asChild = false, + loading = false, + loadingText = "Loading...", + children, + ...props + }, + ref, + ) => { const Comp = asChild ? Slot : "button"; + + if (asChild) { + return ( + + {children} + + ); + } + return ( + > + {loading ? ( + <> + + {loadingText} + + ) : ( + children + )} + ); }, );