Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: add loading state to Button component

Bosch4e597724350a
diff --git a/dashboard/src/components/atoms/Button.test.tsx b/dashboard/src/components/atoms/Button.test.tsx
index 8dd9f19c..31e13a80 100644
--- a/dashboard/src/components/atoms/Button.test.tsx
+++ b/dashboard/src/components/atoms/Button.test.tsx
@@ -35,4 +35,17 @@ describe("Button", () => {
render(<Button disabled>Disabled</Button>);
expect(screen.getByRole("button")).toBeDisabled();
});
+
+ it("shows spinner and disables when loading", () => {
+ render(<Button loading>Loading</Button>);
+ const button = screen.getByRole("button");
+ expect(button).toBeDisabled();
+ expect(button.querySelector("svg")).toBeInTheDocument();
+ });
+
+ it("shows spinner alongside text when loading", () => {
+ render(<Button loading>Submit</Button>);
+ expect(screen.getByText("Submit")).toBeInTheDocument();
+ expect(screen.getByRole("button").querySelector("svg")).toBeInTheDocument();
+ });
});
diff --git a/dashboard/src/components/atoms/Button.tsx b/dashboard/src/components/atoms/Button.tsx
index ae322bc8..7b53a189 100644
--- a/dashboard/src/components/atoms/Button.tsx
+++ b/dashboard/src/components/atoms/Button.tsx
@@ -7,6 +7,7 @@ type Size = "sm" | "md" | "lg";
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: Variant;
size?: Size;
+ loading?: boolean;
}
const base =
@@ -29,17 +30,59 @@ const sizes: Record<Size, string> = {
lg: "px-4 py-2 text-base",
};
+// Spinner sizes match button text sizes
+const spinnerSizes: Record<Size, string> = {
+ sm: "h-3 w-3",
+ md: "h-4 w-4",
+ lg: "h-5 w-5",
+};
+
+function Spinner({ size }: { size: Size }) {
+ return (
+ <svg
+ className={`animate-spin ${spinnerSizes[size]}`}
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ >
+ <circle
+ className="opacity-25"
+ cx="12"
+ cy="12"
+ r="10"
+ stroke="currentColor"
+ strokeWidth="4"
+ />
+ <path
+ className="opacity-75"
+ fill="currentColor"
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
+ />
+ </svg>
+ );
+}
+
const Button = forwardRef<HTMLButtonElement, Props>(
(
- { variant = "default", size = "md", className = "", children, ...props },
+ {
+ variant = "default",
+ size = "md",
+ loading = false,
+ className = "",
+ children,
+ disabled,
+ ...props
+ },
ref,
) => {
return (
<button
ref={ref}
className={`${base} ${variants[variant]} ${sizes[size]} ${className}`}
+ disabled={disabled || loading}
{...props}
>
+ {loading && <Spinner size={size} />}
{children}
</button>
);
diff --git a/dashboard/src/pages/ProfilesPage.tsx b/dashboard/src/pages/ProfilesPage.tsx
index 32a562a1..421e1f57 100644
--- a/dashboard/src/pages/ProfilesPage.tsx
+++ b/dashboard/src/pages/ProfilesPage.tsx
@@ -27,6 +27,7 @@ export default function ProfilesPage() {
const [launchPort, setLaunchPort] = useState("9868");
const [launchHeadless, setLaunchHeadless] = useState(false);
const [launchError, setLaunchError] = useState("");
+ const [launchLoading, setLaunchLoading] = useState(false);
const [copyFeedback, setCopyFeedback] = useState("");
const loadProfiles = async () => {
@@ -67,8 +68,9 @@ export default function ProfilesPage() {
};
const handleLaunch = async () => {
- if (!showLaunch) return;
+ if (!showLaunch || launchLoading) return;
setLaunchError("");
+ setLaunchLoading(true);
try {
const payload = {
name: showLaunch,
@@ -88,6 +90,8 @@ export default function ProfilesPage() {
console.error("Launch failed:", e);
const msg = e instanceof Error ? e.message : "Failed to launch instance";
setLaunchError(msg);
+ } finally {
+ setLaunchLoading(false);
}
};
@@ -239,6 +243,7 @@ export default function ProfilesPage() {
<>
<Button
variant="secondary"
+ disabled={launchLoading}
onClick={() => {
setShowLaunch(null);
setLaunchError("");
@@ -246,7 +251,11 @@ export default function ProfilesPage() {
>
Cancel
</Button>
- <Button variant="primary" onClick={handleLaunch}>
+ <Button
+ variant="primary"
+ onClick={handleLaunch}
+ loading={launchLoading}
+ >
Start
</Button>
</>