refactor(cloud): simplify relay install progress

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-06-04 14:03:01 -07:00
1 parent c5a1419fa7
commit aa866a1e9d
4 files changed
+84 -47

No files matched your search

@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it } from "vitest";
import {
completeRelayClientInstallDialogClose,
finishRelayClientInstall,
readRelayClientInstallDialogState,
reportRelayClientInstallProgress,
@@ -37,6 +38,16 @@ describe("relay client install dialog coordinator", () => {
});
finishRelayClientInstall();
expect(readRelayClientInstallDialogState()).toEqual({
status: "closing",
view: {
status: "installing",
version: "2026.5.2",
stage: "downloading",
},
});
completeRelayClientInstallDialogClose();
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
});
@@ -45,6 +56,15 @@ describe("relay client install dialog coordinator", () => {
respondToRelayClientInstallConfirmation(false);
await expect(confirmation).resolves.toBe(false);
expect(readRelayClientInstallDialogState()).toEqual({
status: "closing",
view: {
status: "confirming",
version: "2026.5.2",
},
});
completeRelayClientInstallDialogClose();
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
});
});
+25 -3
View File
@@ -10,6 +10,16 @@ export type RelayClientInstallDialogState =
readonly status: "installing";
readonly version: string;
readonly stage: RelayClientInstallProgressStage;
}
| {
readonly status: "closing";
readonly view:
| { readonly status: "confirming"; readonly version: string }
| {
readonly status: "installing";
readonly version: string;
readonly stage: RelayClientInstallProgressStage;
};
};
const idleState: RelayClientInstallDialogState = { status: "idle" };
@@ -54,7 +64,9 @@ export function respondToRelayClientInstallConfirmation(confirmed: boolean): voi
const resolve = resolveConfirmation;
resolveConfirmation = null;
publish(
confirmed ? { status: "installing", version: state.version, stage: "checking" } : idleState,
confirmed
? { status: "installing", version: state.version, stage: "checking" }
: { status: "closing", view: state },
);
resolve(confirmed);
}
@@ -69,10 +81,20 @@ export function reportRelayClientInstallProgress(event: RelayClientInstallProgre
export function finishRelayClientInstall(): void {
resolveConfirmation?.(false);
resolveConfirmation = null;
publish(idleState);
if (state.status === "confirming" || state.status === "installing") {
publish({ status: "closing", view: state });
}
}
export function completeRelayClientInstallDialogClose(): void {
if (state.status === "closing") {
publish(idleState);
}
}
export function resetRelayClientInstallDialogForTests(): void {
finishRelayClientInstall();
resolveConfirmation?.(false);
resolveConfirmation = null;
publish(idleState);
listeners.clear();
}
@@ -6,6 +6,7 @@ import { render } from "vitest-browser-react";
import {
finishRelayClientInstall,
readRelayClientInstallDialogState,
reportRelayClientInstallProgress,
requestRelayClientInstallConfirmation,
resetRelayClientInstallDialogForTests,
@@ -31,16 +32,16 @@ describe("RelayClientInstallDialog", () => {
.toBeInTheDocument();
reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });
await expect.element(page.getByText("Downloading relay client")).toBeInTheDocument();
await expect
.element(page.getByText("Downloading relay client").first())
.toHaveTextContent("Downloading relay client");
await expect
.element(page.getByText("Downloading relay client").first())
.toHaveAttribute("class", expect.stringContaining("font-medium"));
.element(page.getByRole("progressbar", { name: "Relay client installation progress" }))
.toHaveAttribute("value", "3");
finishRelayClientInstall();
expect(readRelayClientInstallDialogState().status).toBe("closing");
await expect
.element(page.getByRole("heading", { name: "Installing relay client" }))
.not.toBeInTheDocument();
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
});
});
@@ -1,8 +1,9 @@
import { CircleCheckIcon, CircleIcon, DownloadIcon } from "lucide-react";
import { DownloadIcon } from "lucide-react";
import { useSyncExternalStore } from "react";
import type { RelayClientInstallProgressStage } from "@t3tools/contracts";
import {
completeRelayClientInstallDialogClose,
readRelayClientInstallDialogState,
respondToRelayClientInstallConfirmation,
subscribeRelayClientInstallDialog,
@@ -17,8 +18,6 @@ import {
DialogPopup,
DialogTitle,
} from "../ui/dialog";
import { Spinner } from "../ui/spinner";
const installSteps: ReadonlyArray<{
readonly stage: RelayClientInstallProgressStage;
readonly label: string;
@@ -38,20 +37,27 @@ export function RelayClientInstallDialog() {
readRelayClientInstallDialogState,
readRelayClientInstallDialogState,
);
const isConfirming = state.status === "confirming";
const isInstalling = state.status === "installing";
const view = state.status === "closing" ? state.view : state;
const isConfirming = view.status === "confirming";
const isInstalling = view.status === "installing";
const activeStepIndex = isInstalling
? installSteps.findIndex(({ stage }) => stage === state.stage)
? installSteps.findIndex(({ stage }) => stage === view.stage)
: -1;
const activeStep = installSteps[activeStepIndex];
return (
<Dialog
open={state.status !== "idle"}
open={state.status === "confirming" || state.status === "installing"}
onOpenChange={(open) => {
if (!open && isConfirming) {
respondToRelayClientInstallConfirmation(false);
}
}}
onOpenChangeComplete={(open) => {
if (!open) {
completeRelayClientInstallDialogClose();
}
}}
>
<DialogPopup className="max-w-md" showCloseButton={isConfirming}>
<DialogHeader>
@@ -69,43 +75,31 @@ export function RelayClientInstallDialog() {
</DialogHeader>
<DialogPanel scrollFade={false}>
{isInstalling ? (
<ol aria-label="Relay client installation progress" className="space-y-2">
{installSteps.map((step, index) => {
const isComplete = activeStepIndex > index;
const isActive = activeStepIndex === index;
return (
<li
key={step.stage}
aria-current={isActive ? "step" : undefined}
className="flex items-center gap-2.5 rounded-lg px-2 py-1.5 text-sm"
>
{isComplete ? (
<CircleCheckIcon aria-hidden className="size-4 text-success" />
) : isActive ? (
<Spinner aria-hidden className="size-4 text-primary" />
) : (
<CircleIcon aria-hidden className="size-4 text-muted-foreground/55" />
)}
<span
className={isActive ? "font-medium text-foreground" : "text-muted-foreground"}
>
{step.label}
</span>
</li>
);
})}
<li aria-live="polite" className="sr-only">
{activeStepIndex >= 0
? installSteps[activeStepIndex]?.label
: "Starting installation"}
</li>
</ol>
<div className="space-y-2.5">
<div className="flex items-center justify-between gap-3 text-sm">
<p aria-live="polite" className="font-medium text-foreground">
{activeStep?.label}
</p>
<p className="shrink-0 tabular-nums text-muted-foreground">
{activeStepIndex + 1} of {installSteps.length}
</p>
</div>
<progress
aria-label="Relay client installation progress"
className="h-2 w-full appearance-none overflow-hidden rounded-full bg-muted [&::-moz-progress-bar]:rounded-full [&::-moz-progress-bar]:bg-primary [&::-webkit-progress-bar]:rounded-full [&::-webkit-progress-bar]:bg-muted [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-primary"
max={installSteps.length}
value={activeStepIndex + 1}
/>
<p className="text-xs leading-relaxed text-muted-foreground">
Keep T3 Code open while the relay client is installed.
</p>
</div>
) : (
<div className="rounded-xl border border-border/70 bg-muted/35 p-3">
<p className="text-sm font-medium text-foreground">Managed relay client</p>
<p className="mt-1 text-sm leading-relaxed text-muted-foreground">
T3 Code will download and install version{" "}
{state.status === "confirming" ? state.version : ""} locally.
{view.status === "confirming" ? view.version : ""} locally.
</p>
</div>
)}