@devries-cameron20 / t3code-1 / commits / 0b91504aba
Fork 0

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

refactor(web): the archived threads settings page lives in its own file (#22666)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:39 UTC 0b91504aba9d485cec4609948b097dac6426acd7
3 files changed +289 -282
apps/web/src/components/settings/ArchivedThreadsPanel.tsx new
+287
@@ -0,0 +1,287 @@
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";
6 +import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
7 +import {
8 + isAtomCommandInterrupted,
9 + settlePromise,
10 + squashAtomCommandFailure,
11 +} from "@t3tools/client-runtime/state/runtime";
12 +import { useSettingsScope } from "./SettingsScopeContext";
13 +import { useThreadActions } from "../../hooks/useThreadActions";
14 +import { readLocalApi } from "../../localApi";
15 +import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
16 +import { RelativeTime } from "../RelativeTime";
17 +import { Button } from "../ui/button";
18 +import { stackedThreadToast, toastManager } from "../ui/toast";
19 +import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout";
20 +import { searchableSetting } from "./settingsSearch";
21 +import { ProjectFavicon } from "../ProjectFavicon";
22 +
23 +export function ArchivedThreadsPanel() {
24 + const { scope, groups: projectGroups, environments } = useSettingsScope();
25 + const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
26 + const {
27 + snapshots: archivedSnapshots,
28 + error: archiveError,
29 + isLoading: isLoadingArchive,
30 + refresh: refreshArchivedThreads,
31 + } = useArchivedThreadSnapshots(scope.environmentIds);
32 +
33 + const { groups: archivedGroups, hasMultipleEnvironments } = (() => {
34 + const selectedProjectKeys =
35 + scope.kind === "project" || scope.kind === "checkout"
36 + ? new Set(scope.members.map((member) => `${member.environmentId}:${member.id}`))
37 + : null;
38 + const projectsByEnvironmentAndId = new Map(
39 + archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
40 + snapshot.projects
41 + .filter(
42 + (project) =>
43 + selectedProjectKeys === null ||
44 + selectedProjectKeys.has(`${environmentId}:${project.id}`),
45 + )
46 + .map(
47 + (project) => [`${environmentId}:${project.id}`, { ...project, environmentId }] as const,
48 + ),
49 + ),
50 + );
51 + const environmentLabels = new Map(
52 + environments.map((environment) => {
53 + const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
54 + return [environment.environmentId, secondary ? `${primary} (${secondary})` : primary];
55 + }),
56 + );
57 + const threads = archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
58 + snapshot.threads.map((thread) => ({
59 + ...presentThreadShell(environmentId, thread),
60 + environmentLabel: environmentLabels.get(environmentId) ?? environmentId,
61 + })),
62 + );
63 + const hasMultipleEnvironments =
64 + new Set(
65 + threads
66 + .filter((thread) =>
67 + projectsByEnvironmentAndId.has(`${thread.environmentId}:${thread.projectId}`),
68 + )
69 + .map((thread) => thread.environmentId),
70 + ).size > 1;
71 + const logicalGroupsByProjectKey = new Map(
72 + projectGroups.flatMap((group) =>
73 + group.memberProjectRefs.map(
74 + (member) => [`${member.environmentId}:${member.projectId}`, group] as const,
75 + ),
76 + ),
77 + );
78 +
79 + const archivedProjects = Array.from(projectsByEnvironmentAndId.values());
80 + const groups = new Map<
81 + string,
82 + {
83 + readonly project: (typeof archivedProjects)[number];
84 + readonly title: string;
85 + readonly threads: Array<(typeof threads)[number]>;
86 + }
87 + >();
88 + for (const project of archivedProjects) {
89 + const projectThreads: Array<(typeof threads)[number]> = [];
90 + for (const thread of threads) {
91 + if (thread.projectId === project.id && thread.environmentId === project.environmentId) {
92 + projectThreads.push(thread);
93 + }
94 + }
95 + if (projectThreads.length > 0) {
96 + const physicalProjectKey = `${project.environmentId}:${project.id}` as const;
97 + const logicalGroup = hasMultipleEnvironments
98 + ? logicalGroupsByProjectKey.get(physicalProjectKey)
99 + : undefined;
100 + const groupKey = logicalGroup?.projectKey ?? physicalProjectKey;
101 + const group = groups.get(groupKey);
102 + if (group) {
103 + group.threads.push(...projectThreads);
104 + } else {
105 + groups.set(groupKey, {
106 + project,
107 + title: logicalGroup?.displayName ?? project.title,
108 + threads: projectThreads,
109 + });
110 + }
111 + }
112 + }
113 + const sortedGroups = Array.from(groups, ([key, group]) => ({
114 + ...group,
115 + key,
116 + threads: group.threads.toSorted((left, right) => {
117 + const leftKey = left.archivedAt ?? left.createdAt;
118 + const rightKey = right.archivedAt ?? right.createdAt;
119 + return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);
120 + }),
121 + }));
122 + return { groups: sortedGroups, hasMultipleEnvironments };
123 + })();
124 +
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,
137 + );
138 +
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 + }
155 +
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 + };
172 +
173 + return (
174 + <SettingsPageContainer>
175 + {archivedGroups.length === 0 ? (
176 + <SettingsSection
177 + id={isLoadingArchive ? undefined : searchableSetting("archive").id}
178 + title={searchableSetting("archive").title}
179 + >
180 + <SettingsRow
181 + title={
182 + <span className="inline-flex items-center gap-2">
183 + {isLoadingArchive ? (
184 + <Spinner size="sm" tone="muted" />
185 + ) : (
186 + <ArchiveIcon className="size-3.5 text-muted-foreground" />
187 + )}
188 + {isLoadingArchive
189 + ? "Loading archived threads"
190 + : archiveError
191 + ? "Could not load archived threads"
192 + : "No archived threads"}
193 + </span>
194 + }
195 + description={
196 + isLoadingArchive
197 + ? "Checking connected environments."
198 + : (archiveError ?? "Archived threads will appear here.")
199 + }
200 + />
201 + </SettingsSection>
202 + ) : (
203 + archivedGroups.map(({ key, project, title, threads: projectThreads }, index) => (
204 + <SettingsSection
205 + key={key}
206 + id={index === 0 ? searchableSetting("archive").id : undefined}
207 + title={title}
208 + icon={<ProjectFavicon project={project} />}
209 + >
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 + ))}
282 + </SettingsSection>
283 + ))
284 + )}
285 + </SettingsPageContainer>
286 + );
287 +}
apps/web/src/components/settings/SettingsPanels.tsx
+1 -281
@@ -1,10 +1,8 @@
1 import { SettingsGroup } from "./SettingsGroup";
2 -import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
2 import { useScopedSettingsWriteAllowed } from "./useScopedSettings";
4 -import { Spinner } from "~/components/ui/spinner";
3 import { NotificationSettings } from "./NotificationSettings";
4 import { PRIVACY_POLICY_URL } from "../../legalLinks";
7 -import { ArchiveIcon, ArchiveX, CheckIcon, ChevronRightIcon, SettingsIcon } from "lucide-react";
5 +import { CheckIcon, ChevronRightIcon, SettingsIcon } from "lucide-react";
6 import { Link, useNavigate } from "@tanstack/react-router";
7 import type { CSSProperties, ReactNode } from "react";
8 import { useEffect, useEffectEvent, useRef, useState } from "react";
@@ -13,16 +11,8 @@ import {
11 type DesktopUpdateChannel,
12 ProviderDriverKind,
13 type ProviderInstanceId,
16 - type ScopedThreadRef,
14 type SidebarProjectGroupingMode,
15 } from "@t3tools/contracts";
19 -import { scopeThreadRef } from "@t3tools/client-runtime/environment";
20 -import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
21 -import {
22 - isAtomCommandInterrupted,
23 - settlePromise,
24 - squashAtomCommandFailure,
25 -} from "@t3tools/client-runtime/state/runtime";
16 import {
17 DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE,
18 DEFAULT_UNIFIED_SETTINGS,
@@ -89,7 +79,6 @@ import {
79 import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
80 import { useSettingsScope } from "./SettingsScopeContext";
81 import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
92 -import { useThreadActions } from "../../hooks/useThreadActions";
82 import { useDesktopUpdateState } from "../../state/desktopUpdate";
83 import {
84 getCustomModelOptionsByInstance,
@@ -105,8 +94,6 @@ import { ensureLocalApi, readLocalApi } from "../../localApi";
94 import { isMacPlatform } from "../../lib/utils";
95 import { useEnvironmentProviders } from "../../state/environments";
96 import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
108 -import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
109 -import { RelativeTime } from "../RelativeTime";
97 import { Button } from "../ui/button";
98 import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
99 import {
@@ -171,7 +158,6 @@ import {
158 useSettingsSearchTargetId,
159 } from "./settingsLayout";
160 import { searchableSetting } from "./settingsSearch";
174 -import { ProjectFavicon } from "../ProjectFavicon";
161 import { PanelAnimationsPreview } from "./PanelAnimationsPreview";
162
163 const ENVIRONMENT_IDENTIFICATION_LABELS: Record<EnvironmentIdentificationMode, string> = {
@@ -3351,269 +3337,3 @@ export function GeneralSettingsPanel() {
3337 </SettingsPageContainer>
3338 );
3339 }
3354 -
3355 -export function ArchivedThreadsPanel() {
3356 - const { scope, groups: projectGroups, environments } = useSettingsScope();
3357 - const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
3358 - const {
3359 - snapshots: archivedSnapshots,
3360 - error: archiveError,
3361 - isLoading: isLoadingArchive,
3362 - refresh: refreshArchivedThreads,
3363 - } = useArchivedThreadSnapshots(scope.environmentIds);
3364 -
3365 - const { groups: archivedGroups, hasMultipleEnvironments } = (() => {
3366 - const selectedProjectKeys =
3367 - scope.kind === "project" || scope.kind === "checkout"
3368 - ? new Set(scope.members.map((member) => `${member.environmentId}:${member.id}`))
3369 - : null;
3370 - const projectsByEnvironmentAndId = new Map(
3371 - archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
3372 - snapshot.projects
3373 - .filter(
3374 - (project) =>
3375 - selectedProjectKeys === null ||
3376 - selectedProjectKeys.has(`${environmentId}:${project.id}`),
3377 - )
3378 - .map(
3379 - (project) => [`${environmentId}:${project.id}`, { ...project, environmentId }] as const,
3380 - ),
3381 - ),
3382 - );
3383 - const environmentLabels = new Map(
3384 - environments.map((environment) => {
3385 - const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
3386 - return [environment.environmentId, secondary ? `${primary} (${secondary})` : primary];
3387 - }),
3388 - );
3389 - const threads = archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
3390 - snapshot.threads.map((thread) => ({
3391 - ...presentThreadShell(environmentId, thread),
3392 - environmentLabel: environmentLabels.get(environmentId) ?? environmentId,
3393 - })),
3394 - );
3395 - const hasMultipleEnvironments =
3396 - new Set(
3397 - threads
3398 - .filter((thread) =>
3399 - projectsByEnvironmentAndId.has(`${thread.environmentId}:${thread.projectId}`),
3400 - )
3401 - .map((thread) => thread.environmentId),
3402 - ).size > 1;
3403 - const logicalGroupsByProjectKey = new Map(
3404 - projectGroups.flatMap((group) =>
3405 - group.memberProjectRefs.map(
3406 - (member) => [`${member.environmentId}:${member.projectId}`, group] as const,
3407 - ),
3408 - ),
3409 - );
3410 -
3411 - const archivedProjects = Array.from(projectsByEnvironmentAndId.values());
3412 - const groups = new Map<
3413 - string,
3414 - {
3415 - readonly project: (typeof archivedProjects)[number];
3416 - readonly title: string;
3417 - readonly threads: Array<(typeof threads)[number]>;
3418 - }
3419 - >();
3420 - for (const project of archivedProjects) {
3421 - const projectThreads: Array<(typeof threads)[number]> = [];
3422 - for (const thread of threads) {
3423 - if (thread.projectId === project.id && thread.environmentId === project.environmentId) {
3424 - projectThreads.push(thread);
3425 - }
3426 - }
3427 - if (projectThreads.length > 0) {
3428 - const physicalProjectKey = `${project.environmentId}:${project.id}` as const;
3429 - const logicalGroup = hasMultipleEnvironments
3430 - ? logicalGroupsByProjectKey.get(physicalProjectKey)
3431 - : undefined;
3432 - const groupKey = logicalGroup?.projectKey ?? physicalProjectKey;
3433 - const group = groups.get(groupKey);
3434 - if (group) {
3435 - group.threads.push(...projectThreads);
3436 - } else {
3437 - groups.set(groupKey, {
3438 - project,
3439 - title: logicalGroup?.displayName ?? project.title,
3440 - threads: projectThreads,
3441 - });
3442 - }
3443 - }
3444 - }
3445 - const sortedGroups = Array.from(groups, ([key, group]) => ({
3446 - ...group,
3447 - key,
3448 - threads: group.threads.toSorted((left, right) => {
3449 - const leftKey = left.archivedAt ?? left.createdAt;
3450 - const rightKey = right.archivedAt ?? right.createdAt;
3451 - return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);
3452 - }),
3453 - }));
3454 - return { groups: sortedGroups, hasMultipleEnvironments };
3455 - })();
3456 -
3457 - const handleArchivedThreadContextMenu = async (
3458 - threadRef: ScopedThreadRef,
3459 - position: { x: number; y: number },
3460 - ) => {
3461 - const api = readLocalApi();
3462 - if (!api) return;
3463 - const clicked = await api.contextMenu.show(
3464 - [
3465 - { id: "unarchive", label: "Unarchive" },
3466 - { id: "delete", label: "Delete", destructive: true },
3467 - ],
3468 - position,
3469 - );
3470 -
3471 - if (clicked === "unarchive") {
3472 - const result = await unarchiveThread(threadRef);
3473 - if (result._tag === "Success") {
3474 - refreshArchivedThreads();
3475 - } else if (!isAtomCommandInterrupted(result)) {
3476 - const error = squashAtomCommandFailure(result);
3477 - toastManager.add(
3478 - stackedThreadToast({
3479 - type: "error",
3480 - title: "Failed to unarchive thread",
3481 - description: error instanceof Error ? error.message : "An error occurred.",
3482 - }),
3483 - );
3484 - }
3485 - return;
3486 - }
3487 -
3488 - if (clicked === "delete") {
3489 - const result = await confirmAndDeleteThread(threadRef);
3490 - if (result._tag === "Success") {
3491 - refreshArchivedThreads();
3492 - } else if (!isAtomCommandInterrupted(result)) {
3493 - const error = squashAtomCommandFailure(result);
3494 - toastManager.add(
3495 - stackedThreadToast({
3496 - type: "error",
3497 - title: "Failed to delete thread",
3498 - description: error instanceof Error ? error.message : "An error occurred.",
3499 - }),
3500 - );
3501 - }
3502 - }
3503 - };
3504 -
3505 - return (
3506 - <SettingsPageContainer>
3507 - {archivedGroups.length === 0 ? (
3508 - <SettingsSection
3509 - id={isLoadingArchive ? undefined : searchableSetting("archive").id}
3510 - title={searchableSetting("archive").title}
3511 - >
3512 - <SettingsRow
3513 - title={
3514 - <span className="inline-flex items-center gap-2">
3515 - {isLoadingArchive ? (
3516 - <Spinner size="sm" tone="muted" />
3517 - ) : (
3518 - <ArchiveIcon className="size-3.5 text-muted-foreground" />
3519 - )}
3520 - {isLoadingArchive
3521 - ? "Loading archived threads"
3522 - : archiveError
3523 - ? "Could not load archived threads"
3524 - : "No archived threads"}
3525 - </span>
3526 - }
3527 - description={
3528 - isLoadingArchive
3529 - ? "Checking connected environments."
3530 - : (archiveError ?? "Archived threads will appear here.")
3531 - }
3532 - />
3533 - </SettingsSection>
3534 - ) : (
3535 - archivedGroups.map(({ key, project, title, threads: projectThreads }, index) => (
3536 - <SettingsSection
3537 - key={key}
3538 - id={index === 0 ? searchableSetting("archive").id : undefined}
3539 - title={title}
3540 - icon={<ProjectFavicon project={project} />}
3541 - >
3542 - {projectThreads.map((thread) => (
3543 - <SettingsRow
3544 - key={`${thread.environmentId}:${thread.id}`}
3545 - onContextMenu={(event) => {
3546 - event.preventDefault();
3547 - void (async () => {
3548 - const result = await settlePromise(() =>
3549 - handleArchivedThreadContextMenu(
3550 - scopeThreadRef(thread.environmentId, thread.id),
3551 - {
3552 - x: event.clientX,
3553 - y: event.clientY,
3554 - },
3555 - ),
3556 - );
3557 - if (result._tag === "Failure") {
3558 - const error = squashAtomCommandFailure(result);
3559 - toastManager.add(
3560 - stackedThreadToast({
3561 - type: "error",
3562 - title: "Archived thread action failed",
3563 - description:
3564 - error instanceof Error ? error.message : "An error occurred.",
3565 - }),
3566 - );
3567 - }
3568 - })();
3569 - }}
3570 - title={thread.title}
3571 - description={
3572 - <span className={hasMultipleEnvironments ? "block truncate" : undefined}>
3573 - {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}
3574 - Archived <RelativeTime timestamp={thread.archivedAt ?? thread.createdAt} />
3575 - {" \u00b7 Created "}
3576 - <RelativeTime timestamp={thread.createdAt} />
3577 - </span>
3578 - }
3579 - control={
3580 - <Button
3581 - type="button"
3582 - variant="outline"
3583 - size="sm"
3584 - className="shrink-0"
3585 - onClick={() => {
3586 - void (async () => {
3587 - const result = await unarchiveThread(
3588 - scopeThreadRef(thread.environmentId, thread.id),
3589 - );
3590 - if (result._tag === "Success") {
3591 - refreshArchivedThreads();
3592 - return;
3593 - }
3594 - if (!isAtomCommandInterrupted(result)) {
3595 - const error = squashAtomCommandFailure(result);
3596 - toastManager.add(
3597 - stackedThreadToast({
3598 - type: "error",
3599 - title: "Failed to unarchive thread",
3600 - description:
3601 - error instanceof Error ? error.message : "An error occurred.",
3602 - }),
3603 - );
3604 - }
3605 - })();
3606 - }}
3607 - >
3608 - <ArchiveX className="size-3.5" />
3609 - <span>Unarchive</span>
3610 - </Button>
3611 - }
3612 - />
3613 - ))}
3614 - </SettingsSection>
3615 - ))
3616 - )}
3617 - </SettingsPageContainer>
3618 - );
3619 -}
apps/web/src/routes/settings.archived.tsx
+1 -1
@@ -1,6 +1,6 @@
1 import { createFileRoute } from "@tanstack/react-router";
2
3 -import { ArchivedThreadsPanel } from "../components/settings/SettingsPanels";
3 +import { ArchivedThreadsPanel } from "../components/settings/ArchivedThreadsPanel";
4
5 export const Route = createFileRoute("/settings/archived")({
6 component: ArchivedThreadsPanel,