Skip to content

Commit 08c0935

Browse files
committed
fix(web): confirm every thread unpin path
1 parent f3ae654 commit 08c0935

9 files changed

Lines changed: 139 additions & 52 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ function ChatViewContent(props: ChatViewProps) {
12731273
const threadSyncPhase = routeKind === "server" ? (props.threadSyncPhase ?? null) : null;
12741274
const threadDetailLoading = threadSyncPhase === "loading";
12751275
const handleNewThread = useNewThreadHandler();
1276-
const { settleThread, pinThread, unpinThread } = useThreadActions();
1276+
const { settleThread, pinThread, confirmAndUnpinThread } = useThreadActions();
12771277
const routeThreadRef = useMemo(
12781278
() => scopeThreadRef(environmentId, threadId),
12791279
[environmentId, threadId],
@@ -5146,17 +5146,19 @@ function ChatViewContent(props: ChatViewProps) {
51465146
event.stopPropagation();
51475147
if (!isServerThread || !activeThreadRef || !supportsPinning) return;
51485148
const pinned = activeThreadPinned;
5149-
void (pinned ? unpinThread(activeThreadRef) : pinThread(activeThreadRef)).then((result) => {
5150-
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
5151-
const error = squashAtomCommandFailure(result);
5152-
toastManager.add(
5153-
stackedThreadToast({
5154-
type: "error",
5155-
title: pinned ? "Failed to unpin thread" : "Failed to pin thread",
5156-
description: error instanceof Error ? error.message : "An error occurred.",
5157-
}),
5158-
);
5159-
});
5149+
void (pinned ? confirmAndUnpinThread(activeThreadRef) : pinThread(activeThreadRef)).then(
5150+
(result) => {
5151+
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
5152+
const error = squashAtomCommandFailure(result);
5153+
toastManager.add(
5154+
stackedThreadToast({
5155+
type: "error",
5156+
title: pinned ? "Failed to unpin thread" : "Failed to pin thread",
5157+
description: error instanceof Error ? error.message : "An error occurred.",
5158+
}),
5159+
);
5160+
},
5161+
);
51605162
return;
51615163
}
51625164

@@ -5284,7 +5286,7 @@ function ChatViewContent(props: ChatViewProps) {
52845286
settleThread,
52855287
supportsPinning,
52865288
supportsSettlement,
5287-
unpinThread,
5289+
confirmAndUnpinThread,
52885290
toggleRightPanel,
52895291
toggleRightPanelMaximized,
52905292
toggleTerminalVisibility,

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,6 @@ export default function Sidebar() {
17401740
const autoSettleMode = useClientSettings((s) => s.sidebarAutoSettleMode);
17411741
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
17421742
const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive);
1743-
const confirmThreadUnpin = useClientSettings((s) => s.confirmThreadUnpin);
17441743
const sidebarProjectSortOrder = useClientSettings((s) => s.sidebarProjectSortOrder);
17451744
const timestampFormat = useClientSettings((s) => s.timestampFormat);
17461745
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
@@ -1750,7 +1749,7 @@ export default function Sidebar() {
17501749
snoozeThread,
17511750
unsnoozeThread,
17521751
pinThread,
1753-
unpinThread,
1752+
confirmAndUnpinThread,
17541753
reorderPinnedThread,
17551754
archiveThread,
17561755
deleteThread,
@@ -2710,22 +2709,7 @@ export default function Sidebar() {
27102709
const attemptUnpin = useCallback(
27112710
(threadRef: ScopedThreadRef) => {
27122711
void (async () => {
2713-
if (confirmThreadUnpin) {
2714-
const api = readLocalApi();
2715-
const thread = threadByKeyRef.current.get(scopedThreadKey(threadRef));
2716-
if (api) {
2717-
const confirmed = await settlePromise(() =>
2718-
api.dialogs.confirm(
2719-
[
2720-
`Unpin thread "${thread?.title ?? "this thread"}"?`,
2721-
"This will move the thread out of your pinned section.",
2722-
].join("\n"),
2723-
),
2724-
);
2725-
if (confirmed._tag === "Failure" || !confirmed.value) return;
2726-
}
2727-
}
2728-
const result = await unpinThread(threadRef);
2712+
const result = await confirmAndUnpinThread(threadRef);
27292713
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
27302714
const error = squashAtomCommandFailure(result);
27312715
toastManager.add(
@@ -2738,7 +2722,7 @@ export default function Sidebar() {
27382722
}
27392723
})();
27402724
},
2741-
[confirmThreadUnpin, unpinThread],
2725+
[confirmAndUnpinThread],
27422726
);
27432727

27442728
const handlePinnedDragEnd = useCallback(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,15 @@ export function useSettingsRestore(onRestored?: () => void) {
526526
...(settings.addProjectBaseDirectory !== DEFAULT_UNIFIED_SETTINGS.addProjectBaseDirectory
527527
? ["Add project base directory"]
528528
: []),
529+
...(settings.confirmThreadUnpin !== DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin
530+
? ["Unpin confirmation"]
531+
: []),
529532
...(settings.confirmThreadArchive !== DEFAULT_UNIFIED_SETTINGS.confirmThreadArchive
530533
? ["Archive confirmation"]
531534
: []),
532535
...(settings.confirmThreadDelete !== DEFAULT_UNIFIED_SETTINGS.confirmThreadDelete
533536
? ["Delete confirmation"]
534537
: []),
535-
...(settings.confirmThreadUnpin !== DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin
536-
? ["Unpin confirmation"]
537-
: []),
538538
...(settings.confirmQuit !== DEFAULT_UNIFIED_SETTINGS.confirmQuit
539539
? ["Quit confirmation"]
540540
: []),

‎apps/web/src/components/settings/settingsSearch.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ describe("searchSettings", () => {
5656
]);
5757
});
5858

59+
it("lists thread confirmations in panel order", () => {
60+
expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
61+
"unpin-confirmation",
62+
"archive-confirmation",
63+
"delete-confirmation",
64+
]);
65+
});
66+
5967
it("returns no results for an empty query", () => {
6068
expect(searchSettings(" ", ITEMS)).toEqual([]);
6169
});

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function useThreadActionMenu(input: {
7171
snoozeThread,
7272
unsnoozeThread,
7373
pinThread,
74-
unpinThread,
74+
confirmAndUnpinThread,
7575
archiveThread,
7676
deleteThread,
7777
} = useThreadActions();
@@ -84,7 +84,6 @@ export function useThreadActionMenu(input: {
8484
const autoSettleMode = useClientSettings((s) => s.sidebarAutoSettleMode);
8585
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
8686
const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive);
87-
const confirmThreadUnpin = useClientSettings((s) => s.confirmThreadUnpin);
8887
const timestampFormat = useClientSettings((s) => s.timestampFormat);
8988
const { copyToClipboard: copyPathToClipboard } = useCopyToClipboard<{ path: string }>({
9089
onCopy: ({ path }) => {
@@ -217,18 +216,7 @@ export function useThreadActionMenu(input: {
217216
await reportFailure("Failed to pin thread", () => pinThread(threadRef));
218217
return;
219218
case "unpin": {
220-
if (confirmThreadUnpin) {
221-
const confirmed = await settlePromise(() =>
222-
api.dialogs.confirm(
223-
[
224-
`Unpin thread "${thread.title}"?`,
225-
"This will move the thread out of your pinned section.",
226-
].join("\n"),
227-
),
228-
);
229-
if (confirmed._tag === "Failure" || !confirmed.value) return;
230-
}
231-
await reportFailure("Failed to unpin thread", () => unpinThread(threadRef));
219+
await reportFailure("Failed to unpin thread", () => confirmAndUnpinThread(threadRef));
232220
return;
233221
}
234222
case "rename":
@@ -328,7 +316,7 @@ export function useThreadActionMenu(input: {
328316
changeRequest,
329317
confirmThreadArchive,
330318
confirmThreadDelete,
331-
confirmThreadUnpin,
319+
confirmAndUnpinThread,
332320
copyBranchToClipboard,
333321
copyPathToClipboard,
334322
copyThreadIdToClipboard,
@@ -342,7 +330,6 @@ export function useThreadActionMenu(input: {
342330
snoozeThread,
343331
threadRef,
344332
timestampFormat,
345-
unpinThread,
346333
unsettleThread,
347334
unsnoozeThread,
348335
updateThreadMetadata,

‎apps/web/src/hooks/useThreadActions.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { ThreadArchiveBlockedError } from "./useThreadActions";
4+
import { requestThreadUnpinConfirmation, ThreadArchiveBlockedError } from "./useThreadActions";
55

66
describe("ThreadArchiveBlockedError", () => {
77
it("keeps the blocked thread context with the fixed message", () => {
@@ -17,3 +17,57 @@ describe("ThreadArchiveBlockedError", () => {
1717
expect(error.message).toBe("Cannot archive a running thread.");
1818
});
1919
});
20+
21+
describe("requestThreadUnpinConfirmation", () => {
22+
it("skips the dialog when confirmation is disabled", async () => {
23+
let callCount = 0;
24+
const result = await requestThreadUnpinConfirmation({
25+
enabled: false,
26+
title: "Pinned thread",
27+
confirm: async () => {
28+
callCount += 1;
29+
return false;
30+
},
31+
});
32+
33+
expect(result).toMatchObject({ _tag: "Success", value: true });
34+
expect(callCount).toBe(0);
35+
});
36+
37+
it("degrades gracefully when dialogs are unavailable", async () => {
38+
const result = await requestThreadUnpinConfirmation({
39+
enabled: true,
40+
title: "Pinned thread",
41+
confirm: null,
42+
});
43+
44+
expect(result).toMatchObject({ _tag: "Success", value: true });
45+
});
46+
47+
it("uses the thread title and returns the user's decision", async () => {
48+
let message = "";
49+
const result = await requestThreadUnpinConfirmation({
50+
enabled: true,
51+
title: "Release prep",
52+
confirm: async (nextMessage) => {
53+
message = nextMessage;
54+
return false;
55+
},
56+
});
57+
58+
expect(message).toBe(
59+
'Unpin thread "Release prep"?\nThis will move the thread out of your pinned section.',
60+
);
61+
expect(result).toMatchObject({ _tag: "Success", value: false });
62+
});
63+
64+
it("keeps dialog failures observable", async () => {
65+
const result = await requestThreadUnpinConfirmation({
66+
enabled: true,
67+
title: "Pinned thread",
68+
confirm: () => Promise.reject(new Error("dialog unavailable")),
69+
});
70+
71+
expect(result._tag).toBe("Failure");
72+
});
73+
});

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,26 @@ export class ThreadPinReorderUnsupportedError extends Schema.TaggedErrorClass<Th
136136
}
137137
}
138138

139+
export async function requestThreadUnpinConfirmation(input: {
140+
enabled: boolean;
141+
title: string;
142+
confirm: ((message: string) => Promise<boolean>) | null;
143+
}) {
144+
const { confirm } = input;
145+
if (!input.enabled || confirm === null) {
146+
return AsyncResult.success(true);
147+
}
148+
149+
return settlePromise(() =>
150+
confirm(
151+
[
152+
`Unpin thread "${input.title}"?`,
153+
"This will move the thread out of your pinned section.",
154+
].join("\n"),
155+
),
156+
);
157+
}
158+
139159
export function useThreadActions() {
140160
const closeTerminal = useAtomCommand(terminalEnvironment.close);
141161
const archiveThreadMutation = useAtomCommand(threadEnvironment.archive, {
@@ -177,6 +197,7 @@ export function useThreadActions() {
177197
});
178198
const sidebarThreadSortOrder = useClientSettings((settings) => settings.sidebarThreadSortOrder);
179199
const confirmThreadDelete = useClientSettings((settings) => settings.confirmThreadDelete);
200+
const confirmThreadUnpin = useClientSettings((settings) => settings.confirmThreadUnpin);
180201
const clearComposerDraftForThread = useComposerDraftStore((store) => store.clearDraftThread);
181202
const clearProjectDraftThreadById = useComposerDraftStore(
182203
(store) => store.clearProjectDraftThreadById,
@@ -590,6 +611,26 @@ export function useThreadActions() {
590611
[unpinThreadMutation],
591612
);
592613

614+
const confirmAndUnpinThread = useCallback(
615+
async (target: ScopedThreadRef) => {
616+
const localApi = readLocalApi();
617+
const resolved = resolveThreadTarget(target);
618+
const confirmationResult = await requestThreadUnpinConfirmation({
619+
enabled: confirmThreadUnpin,
620+
title: resolved?.thread.title ?? "this thread",
621+
confirm: localApi ? (message) => localApi.dialogs.confirm(message) : null,
622+
});
623+
if (confirmationResult._tag === "Failure") {
624+
return confirmationResult;
625+
}
626+
if (!confirmationResult.value) {
627+
return AsyncResult.success(undefined);
628+
}
629+
return unpinThread(target);
630+
},
631+
[confirmThreadUnpin, resolveThreadTarget, unpinThread],
632+
);
633+
593634
const reorderPinnedThread = useCallback(
594635
async (target: ScopedThreadRef, orderKey: string) => {
595636
// Callers (the sidebar drag handler) only enable dragging on
@@ -709,11 +750,13 @@ export function useThreadActions() {
709750
unsnoozeThread,
710751
pinThread,
711752
unpinThread,
753+
confirmAndUnpinThread,
712754
reorderPinnedThread,
713755
}),
714756
[
715757
archiveThread,
716758
confirmAndDeleteThread,
759+
confirmAndUnpinThread,
717760
deleteThread,
718761
pinThread,
719762
reorderPinnedThread,

‎docs/user/thread-sidebar.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Pin a thread from its context menu to keep it in the pinned section above your a
44
`mod+shift+p` pins or unpins the thread you have open. Pinned threads are shown independently of
55
their project, including when you connect to more than one environment.
66

7+
To require confirmation before unpinning, enable **Settings → General → Unpin confirmation**. The
8+
confirmation applies to the sidebar controls, thread menus, and the `mod+shift+p` shortcut.
9+
710
Pinned threads follow the auto-settle policy in **Settings → General**. Choose exactly one policy:
811
settle when a pull request merges or closes, settle after a configurable period of inactivity, or
912
never auto-settle. **Never** leaves every automatic path off, so threads settle only when you choose

‎packages/contracts/src/settings.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ describe("ClientSettings sidebar", () => {
141141
);
142142
});
143143

144+
it("keeps unpin confirmation opt-in and patchable", () => {
145+
expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
146+
expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
147+
expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
148+
});
149+
144150
it("allows auto-settle by inactivity to be disabled", () => {
145151
expect(
146152
decodeClientSettings({ sidebarAutoSettleAfterDays: null }).sidebarAutoSettleAfterDays,

0 commit comments

Comments
 (0)