@devries-cameron20 / t3code Mirror · read-only / commits / c864b1c1e1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 02:00 UTC

feat(web): delete archived threads from the archive page (#22160)

Lakshmi Tanmay committed Nov 7, 2026 at 16:17 UTC c864b1c1e110294607303c19a8595a24a209b4b4
3 files changed +120 -120
apps/web/src/components/settings/ArchivedThreadsPanel.tsx
+106 -118
@@ -1,10 +1,10 @@
1 import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
2 import { Spinner } from "~/components/ui/spinner";
3 -import { ArchiveIcon, ArchiveX } from "lucide-react";
4 -import { type ScopedThreadRef } from "@t3tools/contracts";
5 -import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3 +import { ArchiveIcon, ArchiveX, Trash2Icon } from "lucide-react";
4 +import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";
5 import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
6 import {
7 + type AtomCommandResult,
8 isAtomCommandInterrupted,
9 settlePromise,
10 squashAtomCommandFailure,
@@ -20,9 +20,20 @@ import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsL
20 import { searchableSetting } from "./settingsSearch";
21 import { ProjectFavicon } from "../ProjectFavicon";
22
23 +import { useRef, useState } from "react";
24 +import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
25 +
26 +const ARCHIVE_ACTIONS = [
27 + { action: "unarchive", label: "Unarchive", Icon: ArchiveX },
28 + { action: "delete", label: "Delete", Icon: Trash2Icon },
29 +] as const;
30 +type ArchiveAction = (typeof ARCHIVE_ACTIONS)[number]["action"];
31 +
32 export function ArchivedThreadsPanel() {
33 const { scope, groups: projectGroups, environments } = useSettingsScope();
34 const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
35 + const pendingActionsRef = useRef(new Set<string>());
36 + const [pendingKeys, setPendingKeys] = useState<ReadonlySet<string>>(() => new Set());
37 const {
38 snapshots: archivedSnapshots,
39 error: archiveError,
@@ -122,52 +133,57 @@ export function ArchivedThreadsPanel() {
133 return { groups: sortedGroups, hasMultipleEnvironments };
134 })();
135
125 - const handleArchivedThreadContextMenu = async (
126 - threadRef: ScopedThreadRef,
127 - position: { x: number; y: number },
128 - ) => {
129 - const api = readLocalApi();
130 - if (!api) return;
131 - const clicked = await api.contextMenu.show(
132 - [
133 - { id: "unarchive", label: "Unarchive" },
134 - { id: "delete", label: "Delete", destructive: true },
135 - ],
136 - position,
136 + type ArchivedThread = (typeof archivedGroups)[number]["threads"][number];
137 +
138 + const reportFailure = (result: AtomCommandResult<unknown, unknown> | null, title: string) => {
139 + if (result?._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
140 + const error = squashAtomCommandFailure(result);
141 + toastManager.add(
142 + stackedThreadToast({
143 + type: "error",
144 + title,
145 + description: error instanceof Error ? error.message : "An error occurred.",
146 + }),
147 );
148 + };
149
139 - if (clicked === "unarchive") {
140 - const result = await unarchiveThread(threadRef);
141 - if (result._tag === "Success") {
142 - refreshArchivedThreads();
143 - } else if (!isAtomCommandInterrupted(result)) {
144 - const error = squashAtomCommandFailure(result);
145 - toastManager.add(
146 - stackedThreadToast({
147 - type: "error",
148 - title: "Failed to unarchive thread",
149 - description: error instanceof Error ? error.message : "An error occurred.",
150 - }),
151 - );
152 - }
153 - return;
154 - }
150 + const handleThreadAction = async (action: ArchiveAction, thread: ArchivedThread) => {
151 + const target = scopeThreadRef(thread.environmentId, thread.id);
152 + const key = scopedThreadKey(target);
153 + // Context menus can outlive their render, so checks and cleanup use the live set.
154 + const pending = pendingActionsRef.current;
155 + if (pending.has(key)) return;
156 + pending.add(key);
157 + setPendingKeys(new Set(pending));
158 + const result = await settlePromise(async () => {
159 + const result = await (action === "unarchive"
160 + ? unarchiveThread(target)
161 + : confirmAndDeleteThread(target, thread.title));
162 + if (result._tag === "Success") refreshArchivedThreads();
163 + return result;
164 + }).finally(() => {
165 + pending.delete(key);
166 + setPendingKeys(new Set(pending));
167 + });
168 + reportFailure(result._tag === "Failure" ? result : result.value, `Failed to ${action} thread`);
169 + };
170
156 - if (clicked === "delete") {
157 - const result = await confirmAndDeleteThread(threadRef);
158 - if (result._tag === "Success") {
159 - refreshArchivedThreads();
160 - } else if (!isAtomCommandInterrupted(result)) {
161 - const error = squashAtomCommandFailure(result);
162 - toastManager.add(
163 - stackedThreadToast({
164 - type: "error",
165 - title: "Failed to delete thread",
166 - description: error instanceof Error ? error.message : "An error occurred.",
167 - }),
168 - );
169 - }
170 - }
171 + const handleContextMenu = async (thread: ArchivedThread, position: { x: number; y: number }) => {
172 + const pending = pendingActionsRef.current;
173 + if (pending.has(scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)))) return;
174 + const result = await settlePromise(async () => {
175 + const clicked = await readLocalApi()?.contextMenu.show(
176 + ARCHIVE_ACTIONS.map(({ action, label }) => ({
177 + id: action,
178 + label,
179 + destructive: action === "delete",
180 + })),
181 + position,
182 + );
183 + if (clicked === "unarchive" || clicked === "delete")
184 + await handleThreadAction(clicked, thread);
185 + });
186 + reportFailure(result, "Archived thread action failed");
187 };
188
189 return (
@@ -207,78 +223,50 @@ export function ArchivedThreadsPanel() {
223 title={title}
224 icon={<ProjectFavicon project={project} />}
225 >
210 - {projectThreads.map((thread) => (
211 - <SettingsRow
212 - key={`${thread.environmentId}:${thread.id}`}
213 - onContextMenu={(event) => {
214 - event.preventDefault();
215 - void (async () => {
216 - const result = await settlePromise(() =>
217 - handleArchivedThreadContextMenu(
218 - scopeThreadRef(thread.environmentId, thread.id),
219 - {
220 - x: event.clientX,
221 - y: event.clientY,
222 - },
223 - ),
224 - );
225 - if (result._tag === "Failure") {
226 - const error = squashAtomCommandFailure(result);
227 - toastManager.add(
228 - stackedThreadToast({
229 - type: "error",
230 - title: "Archived thread action failed",
231 - description:
232 - error instanceof Error ? error.message : "An error occurred.",
233 - }),
234 - );
235 - }
236 - })();
237 - }}
238 - title={thread.title}
239 - description={
240 - <span className={hasMultipleEnvironments ? "block truncate" : undefined}>
241 - {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}
242 - Archived <RelativeTime timestamp={thread.archivedAt ?? thread.createdAt} />
243 - {" \u00b7 Created "}
244 - <RelativeTime timestamp={thread.createdAt} />
245 - </span>
246 - }
247 - control={
248 - <Button
249 - type="button"
250 - variant="outline"
251 - size="sm"
252 - className="shrink-0"
253 - onClick={() => {
254 - void (async () => {
255 - const result = await unarchiveThread(
256 - scopeThreadRef(thread.environmentId, thread.id),
257 - );
258 - if (result._tag === "Success") {
259 - refreshArchivedThreads();
260 - return;
261 - }
262 - if (!isAtomCommandInterrupted(result)) {
263 - const error = squashAtomCommandFailure(result);
264 - toastManager.add(
265 - stackedThreadToast({
266 - type: "error",
267 - title: "Failed to unarchive thread",
268 - description:
269 - error instanceof Error ? error.message : "An error occurred.",
270 - }),
271 - );
272 - }
273 - })();
274 - }}
275 - >
276 - <ArchiveX className="size-3.5" />
277 - <span>Unarchive</span>
278 - </Button>
279 - }
280 - />
281 - ))}
226 + {projectThreads.map((thread) => {
227 + const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
228 + return (
229 + <SettingsRow
230 + key={`${thread.environmentId}:${thread.id}`}
231 + onContextMenu={(event) => {
232 + event.preventDefault();
233 + void handleContextMenu(thread, { x: event.clientX, y: event.clientY });
234 + }}
235 + title={thread.title}
236 + description={
237 + <span className={hasMultipleEnvironments ? "block truncate" : undefined}>
238 + {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}
239 + Archived <RelativeTime timestamp={thread.archivedAt ?? thread.createdAt} />
240 + {" \u00b7 Created "}
241 + <RelativeTime timestamp={thread.createdAt} />
242 + </span>
243 + }
244 + control={
245 + <div className="flex shrink-0 items-center gap-2">
246 + {ARCHIVE_ACTIONS.map(({ action, label, Icon }) => (
247 + <Tooltip key={action}>
248 + <TooltipTrigger
249 + render={
250 + <Button
251 + type="button"
252 + variant={action === "delete" ? "destructive-outline" : "outline"}
253 + size="icon-sm"
254 + aria-label={`${label} ${thread.title}`}
255 + disabled={pendingKeys.has(threadKey)}
256 + onClick={() => void handleThreadAction(action, thread)}
257 + />
258 + }
259 + >
260 + <Icon className="size-3.5" />
261 + </TooltipTrigger>
262 + <TooltipPopup>{label}</TooltipPopup>
263 + </Tooltip>
264 + ))}
265 + </div>
266 + }
267 + />
268 + );
269 + })}
270 </SettingsSection>
271 ))
272 )}
apps/web/src/hooks/useThreadActions.permissions.test.ts
+12
@@ -307,6 +307,18 @@ describe("thread action permissions", () => {
307 },
308 );
309
310 + it("names an archived thread in its delete confirmation and preserves it on cancel", async () => {
311 + state.threads = [];
312 + state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
313 + state.confirm.mockResolvedValue(false);
314 + await useThreadActions().confirmAndDeleteThread(target, "Archived release notes");
315 + expect(state.confirm).toHaveBeenCalledWith(
316 + expect.stringContaining('Delete thread "Archived release notes"?'),
317 + { variant: "destructive" },
318 + );
319 + expect(state.requests).toEqual([]);
320 + });
321 +
322 it("deletes an archived thread only with its own environment's grant", async () => {
323 state.threads = [];
324 seedThreadPanelState(target);
apps/web/src/hooks/useThreadActions.ts
+2 -2
@@ -921,14 +921,14 @@ export function useThreadActions() {
921 (result) => result._tag === "Success",
922 );
923
924 - const confirmAndDeleteThread = async (target: ScopedThreadRef) => {
924 + const confirmAndDeleteThread = async (target: ScopedThreadRef, knownTitle?: string) => {
925 const permissionFailure = threadOperationFailure(target);
926 if (permissionFailure) return permissionFailure;
927 const localApi = readLocalApi();
928 const resolved = resolveThreadTarget(target);
929
930 if (confirmThreadDelete && localApi) {
931 - const title = resolved?.thread.title ?? "this thread";
931 + const title = resolved?.thread.title ?? knownTitle ?? "this thread";
932 const confirmationResult = await settlePromise(() =>
933 localApi.dialogs.confirm(
934 [