Skip to content

Commit 7b8cc83

Browse files
morgmartCarlclaude
committed
fix(polish): confirm a quick community copy once and cover pressed hints
Clicking the community address before its hint rests showed a toast, and the pending hint then opened with a second "Copied" confirmation. A toast now keeps that hint closed until the pointer leaves. Also adds a regression test for pressed triggers keeping their hint closed when focus returns until the user tabs, and updates the Members history contract: dismissal returns to the visit it was opened from, or replaces the Members visit when that visit is unknown, such as after a reload. Signed-off-by: morgmart <[email protected]> Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ab9da62 commit 7b8cc83

4 files changed

Lines changed: 72 additions & 4 deletions

File tree

‎docs/channels.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,13 @@ native acceptance.
786786
through the host navigation owner. Opening creates a visit; browser Back dismisses
787787
and Forward restores the list. Reload restores the same channel and Members,
788788
including the underlying message/thread address when present. Close, Escape and
789-
outside dismissal open the underlying conversation as a new visit, so Back can
790-
recover the list. Profile/DM handoffs dismiss Members without replacing the new
791-
destination, and history traversal never repeats a DM open or membership mutation.
789+
outside dismissal return to the visit Members was opened from, so closing never
790+
adds a visit and Back does not reopen the list. When that visit is unknown, such
791+
as after a reload, dismissal replaces the Members visit with the underlying
792+
conversation instead; Back then steps to the earlier visit of that same
793+
conversation. Profile/DM handoffs replace the Members visit rather than
794+
traversing back, so the new destination and its address stay current, and
795+
history traversal never repeats a DM open or membership mutation.
792796
Search, role filters, menus and confirmations are transient, not address data.
793797
Scoped history still requires the original viewer, joined community and current
794798
channel access. Tabs remain session-owned: navigation preserves them, but this

‎src/app/CommunityAddress.test.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { afterEach, expect, it, vi } from "vitest";
1111
import { CommunityAddress } from "./CommunityAddress";
1212
import type { CommunityReader } from "../features/communities/service";
1313
import { ToastProvider } from "../shared/design-system/ui/Toast";
14+
import { HELPFUL_HINT_REST_MS } from "../shared/design-system/ui/hoverIntent";
1415

1516
const communities: CommunityReader = {
1617
subscribe: () => () => {},
@@ -91,6 +92,44 @@ it("reports clipboard refusal without claiming success and allows retry", async
9192
expect(writeText).toHaveBeenCalledTimes(2);
9293
});
9394

95+
it("a click before the hint rests confirms once, by toast", async () => {
96+
vi.useFakeTimers();
97+
vi.stubGlobal("navigator", {
98+
clipboard: { writeText: vi.fn().mockResolvedValue(undefined) },
99+
});
100+
render(
101+
<ToastProvider>
102+
<CommunityAddress
103+
communities={communities}
104+
community={{ id: "https://community.example", name: "Community" }}
105+
/>
106+
</ToastProvider>,
107+
);
108+
const button = screen.getByRole("button", {
109+
name: "Copy community URL, community.example",
110+
});
111+
fireEvent.mouseEnter(button);
112+
fireEvent.mouseMove(button);
113+
act(() => vi.advanceTimersByTime(100));
114+
fireEvent.pointerDown(button, { pointerType: "mouse" });
115+
fireEvent.mouseDown(button);
116+
fireEvent.pointerUp(button, { pointerType: "mouse" });
117+
fireEvent.mouseUp(button);
118+
await act(async () => fireEvent.click(button));
119+
// The pointer settles after the click, restarting the hint's rest.
120+
fireEvent.mouseMove(button);
121+
act(() => vi.advanceTimersByTime(HELPFUL_HINT_REST_MS));
122+
expect(screen.getAllByText("Community URL copied.")).toHaveLength(2);
123+
expect(screen.queryByRole("tooltip")).toBeNull();
124+
// Leaving ends that confirmation; the next resting hover offers Copy again.
125+
fireEvent.pointerLeave(button, { pointerType: "mouse" });
126+
fireEvent.mouseLeave(button);
127+
fireEvent.mouseEnter(button);
128+
fireEvent.mouseMove(button);
129+
act(() => vi.advanceTimersByTime(HELPFUL_HINT_REST_MS));
130+
expect(screen.getByRole("tooltip")).toHaveTextContent("Copy");
131+
});
132+
94133
it("a later copy result wins and changing community clears the old confirmation", async () => {
95134
let first!: () => void;
96135
let second!: () => void;

‎src/app/CommunityAddress.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function CopyAddress({
5252
const [copied, setCopied] = useState(false);
5353
const [hint, setHint] = useState(false);
5454
const visible = useRef(false);
55+
// A toast already confirmed this copy; the hint must not repeat it.
56+
const toasted = useRef(false);
5557
const pointerType = useRef("");
5658
const attempt = useRef(0);
5759
const notify = useToastNotification();
@@ -68,8 +70,10 @@ function CopyAddress({
6870
await navigator.clipboard.writeText(url);
6971
if (current === attempt.current) {
7072
setCopied(true);
71-
if (!visible.current || pointerType.current === "touch")
73+
if (!visible.current || pointerType.current === "touch") {
74+
toasted.current = true;
7275
notify("Community URL copied.", "success");
76+
}
7377
}
7478
} catch {
7579
if (current === attempt.current)
@@ -91,6 +95,7 @@ function CopyAddress({
9195
follow="pointer"
9296
open={hint}
9397
onOpenChange={(open) => {
98+
if (open && toasted.current) return;
9499
visible.current = open;
95100
setHint(open);
96101
if (!open) setCopied(false);
@@ -114,6 +119,7 @@ function CopyAddress({
114119
pointerType.current = event.pointerType;
115120
}}
116121
onPointerLeave={() => {
122+
toasted.current = false;
117123
visible.current = false;
118124
setHint(false);
119125
setCopied(false);

‎src/shared/design-system/ui/Tooltip.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ describe("hover intent", () => {
147147
expect(screen.getByRole("tooltip")).toHaveTextContent("Go back");
148148
});
149149

150+
it("keeps a pressed trigger's hint closed when focus returns, until Tab", async () => {
151+
render(
152+
<Tooltip content="Go back" hint="familiar">
153+
<button type="button">Back</button>
154+
</Tooltip>,
155+
);
156+
const back = screen.getByRole("button", { name: "Back" });
157+
// A menu opened by the press closes and hands focus back to its trigger.
158+
fireEvent.pointerDown(back, { pointerType: "mouse" });
159+
act(() => back.focus());
160+
await rest(0);
161+
expect(screen.queryByRole("tooltip")).toBeNull();
162+
act(() => back.blur());
163+
fireEvent.keyDown(window, { key: "Tab" });
164+
act(() => back.focus());
165+
await rest(0);
166+
expect(screen.getByRole("tooltip")).toHaveTextContent("Go back");
167+
});
168+
150169
it("opens a neighbor at once while a hint in the same provider is showing", async () => {
151170
render(
152171
<TooltipProvider>

0 commit comments

Comments
 (0)