From 9d4d1bb29f31c2f6373ef89b8924c6fcb5acdbaf Mon Sep 17 00:00:00 2001 From: bfmvsa Date: Sat, 19 Jul 2025 17:45:22 +0200 Subject: [PATCH 1/6] Add loading & loading text params to the button component. --- client/src/components/ui/button.tsx | 38 ++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsx index 8e435c3c8..29b201520 100644 --- a/client/src/components/ui/button.tsx +++ b/client/src/components/ui/button.tsx @@ -38,20 +38,52 @@ 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, loadingText = "Loading...", children, ...props }, ref) => { const Comp = asChild ? Slot : "button"; + + if (asChild) { + return ( + + {children} + + ); + } + return ( + > + {loading ? ( + <> + + {loadingText} + + ) : ( + children + )} + ); }, ); Button.displayName = "Button"; -export { Button }; +export { Button }; \ No newline at end of file From 10039681bea4c2f1f133d924999875338194f5b1 Mon Sep 17 00:00:00 2001 From: bfmvsa Date: Sat, 19 Jul 2025 17:46:15 +0200 Subject: [PATCH 2/6] Update the click handlers of the connect and reconect button to set loading state to buttons. --- client/src/components/Sidebar.tsx | 43 ++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index 938e5b5a3..ae05706be 100644 --- a/client/src/components/Sidebar.tsx +++ b/client/src/components/Sidebar.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback } from "react"; +import React, { useState, useCallback } from "react"; import { Play, ChevronDown, @@ -100,8 +100,37 @@ 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(); + // Reset connecting state when connection status changes + React.useEffect(() => { + if (connectionStatus !== "disconnected") { + setIsConnecting(false); + } + }, [connectionStatus]); + + // Wrapper for onConnect that manages loading state + const handleConnect = useCallback(async () => { + setIsConnecting(true); + try { + await onConnect(); + } finally { + // The useEffect above will reset isConnecting when connectionStatus changes + } + }, [onConnect]); + + // Wrapper for restart that manages loading state + const handleRestart = useCallback(async () => { + setIsConnecting(true); + try { + onDisconnect(); + await onConnect(); + } finally { + // The useEffect above will reset isConnecting when connectionStatus changes + } + }, [onConnect, onDisconnect]); + // Reusable error reporter for copy actions const reportError = useCallback( (error: unknown) => { @@ -625,10 +654,8 @@ const Sidebar = ({
)} {connectionStatus !== "connected" && ( - From aee0965171be801eefc2f20c8bec6409d39b7f92 Mon Sep 17 00:00:00 2001 From: bfmvsa Date: Sat, 19 Jul 2025 18:04:16 +0200 Subject: [PATCH 3/6] Prettier fixes --- client/src/components/Sidebar.tsx | 6 ++--- client/src/components/ui/button.tsx | 42 ++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index ae05706be..d6e53cc74 100644 --- a/client/src/components/Sidebar.tsx +++ b/client/src/components/Sidebar.tsx @@ -667,9 +667,9 @@ const Sidebar = ({ )} {connectionStatus !== "connected" && ( -