Skip to content

Commit de1206e

Browse files
fix(web): show version copy confirmation after clicking
1 parent 6389cde commit de1206e

5 files changed

Lines changed: 72 additions & 71 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, it, vi } from "vite-plus/test";
2+
import { page } from "vite-plus/test/browser";
3+
4+
import { render } from "../../../test/render";
5+
import { APP_VERSION } from "../../branding";
6+
import { AnchoredToastProvider } from "../ui/toast";
7+
import { AboutVersionTitle } from "./AboutVersionTitle";
8+
9+
it("shows copy confirmation when the version is clicked without waiting for a hover tooltip", async () => {
10+
await using screen = await render(
11+
<AnchoredToastProvider>
12+
<AboutVersionTitle />
13+
</AnchoredToastProvider>,
14+
);
15+
using write = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
16+
17+
await screen.getByRole("button", { name: `Copy version ${APP_VERSION}` }).click();
18+
19+
expect(write).toHaveBeenCalledWith(APP_VERSION);
20+
await expect.element(page.getByText(/^Copied!?$/)).toBeVisible();
21+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useRef } from "react";
2+
3+
import { APP_VERSION } from "../../branding";
4+
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
5+
import { showAnchoredCopySuccessToast } from "../ui/anchoredCopyToast";
6+
import { InlineButton } from "../ui/button";
7+
import { stackedThreadToast, toastManager } from "../ui/toast";
8+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
9+
10+
export function AboutVersionTitle() {
11+
const copyButtonRef = useRef<HTMLButtonElement>(null);
12+
const { copyToClipboard } = useCopyToClipboard<void>({
13+
target: "version",
14+
onCopy: () => showAnchoredCopySuccessToast(copyButtonRef),
15+
onError: (error) => {
16+
toastManager.add(
17+
stackedThreadToast({
18+
type: "error",
19+
title: "Could not copy version",
20+
description: error.message,
21+
}),
22+
);
23+
},
24+
});
25+
26+
return (
27+
<span className="inline-flex items-baseline gap-2">
28+
<span>Version</span>
29+
<code className="text-2xs font-medium">
30+
<Tooltip>
31+
<TooltipTrigger
32+
render={
33+
<InlineButton
34+
ref={copyButtonRef}
35+
tone="muted"
36+
aria-label={`Copy version ${APP_VERSION}`}
37+
onClick={() => copyToClipboard(APP_VERSION, undefined)}
38+
>
39+
{APP_VERSION}
40+
</InlineButton>
41+
}
42+
/>
43+
<TooltipPopup>Copy version</TooltipPopup>
44+
</Tooltip>
45+
</code>
46+
</span>
47+
);
48+
}

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
import { createModelSelection } from "@t3tools/shared/model";
2525
import * as Equal from "effect/Equal";
2626
import * as Schema from "effect/Schema";
27-
import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
27+
import { HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
28+
import { AboutVersionTitle } from "./AboutVersionTitle";
2829
import { CliCommandSettingsRow } from "./CliCommandSettingsRow";
2930
import { MobileAppSettingsRow } from "./MobileAppSettingsRow";
3031
import {
@@ -68,10 +69,9 @@ import {
6869
} from "../../providerInstances";
6970
import { ensureLocalApi, readLocalApi } from "../../localApi";
7071
import { isMacPlatform } from "../../lib/utils";
71-
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
7272
import { useEnvironmentProviders } from "../../state/environments";
7373
import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
74-
import { Button, InlineButton } from "../ui/button";
74+
import { Button } from "../ui/button";
7575
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
7676
import { DraftInput } from "../ui/draft-input";
7777
import { Input } from "../ui/input";
@@ -136,43 +136,6 @@ const QUIT_CONFIRMATION_MODE_LABELS: Record<QuitConfirmationMode, string> = {
136136
};
137137

138138
const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
139-
function AboutVersionTitle() {
140-
const { copyToClipboard, isCopied } = useCopyToClipboard<void>({
141-
target: "version",
142-
onError: (error) => {
143-
toastManager.add(
144-
stackedThreadToast({
145-
type: "error",
146-
title: "Could not copy version",
147-
description: error.message,
148-
}),
149-
);
150-
},
151-
});
152-
153-
return (
154-
<span className="inline-flex items-baseline gap-2">
155-
<span>Version</span>
156-
<code className="text-2xs font-medium">
157-
<Tooltip>
158-
<TooltipTrigger
159-
render={
160-
<InlineButton
161-
tone="muted"
162-
aria-label={`Copy version ${APP_VERSION}`}
163-
onClick={() => copyToClipboard(APP_VERSION, undefined)}
164-
>
165-
{APP_VERSION}
166-
</InlineButton>
167-
}
168-
/>
169-
<TooltipPopup>{isCopied ? "Copied" : "Copy version"}</TooltipPopup>
170-
</Tooltip>
171-
</code>
172-
</span>
173-
);
174-
}
175-
176139
function AboutVersionSection() {
177140
const updateState = useDesktopUpdateState();
178141
const [isChangingUpdateChannel, setIsChangingUpdateChannel] = useState(false);

‎apps/web/src/hooks/useCopyToClipboard.browser.test.tsx‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎apps/web/src/hooks/useCopyToClipboard.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ export function useCopyToClipboard<TContext = void>({
227227
},
228228
(error) => {
229229
console.error(error);
230-
setIsCopied(false);
231230
onError?.(error, ctx);
232231
},
233232
);

0 commit comments

Comments
 (0)