Skip to content

Commit 6029cc8

Browse files
voltcrashclaude
andcommitted
feat(web): unarchive or delete all archived threads in a project
Clearing out a project's archive meant clicking each row. Add Unarchive all and Delete all to each project header on the archive page. Delete all asks once with the thread count, then deletes each thread through the same deleteThread path as the row button, so permission checks and failure toasts match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 014b686 commit 6029cc8

1 file changed

Lines changed: 126 additions & 2 deletions

File tree

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

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
type ScopedThreadRef,
2424
type SidebarProjectGroupingMode,
2525
} from "@t3tools/contracts";
26-
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
26+
import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";
2727
import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
2828
import {
2929
isAtomCommandInterrupted,
@@ -59,6 +59,7 @@ import {
5959
import { resolveServerBackgroundActivitySettings } from "@t3tools/shared/backgroundActivitySettings";
6060
import { createModelSelection } from "@t3tools/shared/model";
6161
import * as Duration from "effect/Duration";
62+
import type { AsyncResult } from "effect/reactivity";
6263
import * as Equal from "effect/Equal";
6364
import * as Schema from "effect/Schema";
6465
import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
@@ -97,6 +98,8 @@ import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
9798
import { useSettingsScope } from "./SettingsScopeContext";
9899
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
99100
import { useThreadActions } from "../../hooks/useThreadActions";
101+
import { useClientSettings } from "../../hooks/useSettings";
102+
import { deleteSelectedThreadEntries } from "../Sidebar.logic";
100103
import { useDesktopUpdateState } from "../../state/desktopUpdate";
101104
import {
102105
getCustomModelOptionsByInstance,
@@ -3332,7 +3335,9 @@ export function GeneralSettingsPanel() {
33323335

33333336
export function ArchivedThreadsPanel() {
33343337
const { scope, groups: projectGroups, environments } = useSettingsScope();
3335-
const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
3338+
const { unarchiveThread, deleteThread, confirmAndDeleteThread } = useThreadActions();
3339+
const confirmThreadDelete = useClientSettings((settings) => settings.confirmThreadDelete);
3340+
const [pendingBulkGroupKey, setPendingBulkGroupKey] = useState<string | null>(null);
33363341
const {
33373342
snapshots: archivedSnapshots,
33383343
error: archiveError,
@@ -3464,6 +3469,84 @@ export function ArchivedThreadsPanel() {
34643469
}
34653470
};
34663471

3472+
const handleUnarchiveAllThreads = async (threadRefs: readonly ScopedThreadRef[]) => {
3473+
let firstFailure: AsyncResult.Failure<unknown, unknown> | null = null;
3474+
for (const threadRef of threadRefs) {
3475+
const result = await unarchiveThread(threadRef);
3476+
if (result._tag === "Success") continue;
3477+
if (isAtomCommandInterrupted(result)) break;
3478+
firstFailure ??= result;
3479+
}
3480+
refreshArchivedThreads();
3481+
if (firstFailure !== null) {
3482+
const error = squashAtomCommandFailure(firstFailure);
3483+
toastManager.add(
3484+
stackedThreadToast({
3485+
type: "error",
3486+
title: "Failed to unarchive threads",
3487+
description: error instanceof Error ? error.message : "An error occurred.",
3488+
}),
3489+
);
3490+
}
3491+
};
3492+
3493+
const handleDeleteAllThreads = async (
3494+
threadRefs: readonly ScopedThreadRef[],
3495+
projectTitle: string,
3496+
) => {
3497+
const api = readLocalApi();
3498+
if (!api) return;
3499+
if (confirmThreadDelete) {
3500+
const count = threadRefs.length;
3501+
const confirmed = await settlePromise(() =>
3502+
api.dialogs.confirm(
3503+
[
3504+
`Delete ${count} archived thread${count === 1 ? "" : "s"} in "${projectTitle}"?`,
3505+
"This permanently clears conversation history for these threads.",
3506+
].join("\n"),
3507+
{ variant: "destructive" },
3508+
),
3509+
);
3510+
if (confirmed._tag === "Failure" || !confirmed.value) return;
3511+
}
3512+
const { firstFailure } = await deleteSelectedThreadEntries({
3513+
entries: threadRefs.map((threadRef) => ({
3514+
threadKey: scopedThreadKey(threadRef),
3515+
threadRef,
3516+
})),
3517+
delete: ({ threadRef }, deletedThreadKeys) => deleteThread(threadRef, { deletedThreadKeys }),
3518+
});
3519+
refreshArchivedThreads();
3520+
if (firstFailure !== null) {
3521+
const error = squashAtomCommandFailure(firstFailure);
3522+
toastManager.add(
3523+
stackedThreadToast({
3524+
type: "error",
3525+
title: "Failed to delete threads",
3526+
description: error instanceof Error ? error.message : "An error occurred.",
3527+
}),
3528+
);
3529+
}
3530+
};
3531+
3532+
const runBulkAction = (groupKey: string, action: () => Promise<void>) => {
3533+
setPendingBulkGroupKey(groupKey);
3534+
void (async () => {
3535+
const result = await settlePromise(action);
3536+
setPendingBulkGroupKey(null);
3537+
if (result._tag === "Failure") {
3538+
const error = squashAtomCommandFailure(result);
3539+
toastManager.add(
3540+
stackedThreadToast({
3541+
type: "error",
3542+
title: "Archived thread action failed",
3543+
description: error instanceof Error ? error.message : "An error occurred.",
3544+
}),
3545+
);
3546+
}
3547+
})();
3548+
};
3549+
34673550
const handleArchivedThreadContextMenu = async (
34683551
threadRef: ScopedThreadRef,
34693552
title: string,
@@ -3522,6 +3605,47 @@ export function ArchivedThreadsPanel() {
35223605
id={index === 0 ? searchableSetting("archive").id : undefined}
35233606
title={title}
35243607
icon={<ProjectFavicon project={project} />}
3608+
headerAction={
3609+
<div className="flex items-center gap-1">
3610+
<Button
3611+
type="button"
3612+
size="xs"
3613+
variant="ghost-muted"
3614+
disabled={pendingBulkGroupKey !== null}
3615+
onClick={() =>
3616+
runBulkAction(key, () =>
3617+
handleUnarchiveAllThreads(
3618+
projectThreads.map((thread) =>
3619+
scopeThreadRef(thread.environmentId, thread.id),
3620+
),
3621+
),
3622+
)
3623+
}
3624+
>
3625+
<ArchiveX className="size-3" />
3626+
Unarchive all
3627+
</Button>
3628+
<Button
3629+
type="button"
3630+
size="xs"
3631+
variant="ghost-destructive"
3632+
disabled={pendingBulkGroupKey !== null}
3633+
onClick={() =>
3634+
runBulkAction(key, () =>
3635+
handleDeleteAllThreads(
3636+
projectThreads.map((thread) =>
3637+
scopeThreadRef(thread.environmentId, thread.id),
3638+
),
3639+
title,
3640+
),
3641+
)
3642+
}
3643+
>
3644+
<Trash2Icon className="size-3" />
3645+
Delete all
3646+
</Button>
3647+
</div>
3648+
}
35253649
>
35263650
{projectThreads.map((thread) => (
35273651
<SettingsRow

0 commit comments

Comments
 (0)