Skip to content

Commit 46b7c3e

Browse files
committed
fix(web): deleting a thread skips snoozed and settled fallbacks
1 parent 8648aea commit 46b7c3e

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,65 @@ describe("getFallbackThreadIdAfterDelete", () => {
624624
deletedThreadId: ThreadId.make("thread-active"),
625625
deletedThreadIds: new Set([ThreadId.make("thread-active"), ThreadId.make("thread-newest")]),
626626
sortOrder: "created_at",
627+
now: "2026-03-09T11:00:00.000Z",
627628
});
628629

629630
expect(fallbackThreadId).toBe(ThreadId.make("thread-next"));
630631
});
632+
633+
it.each([
634+
{
635+
state: "snoozed",
636+
overrides: { snoozedUntil: "2026-03-09T14:00:00.000Z" },
637+
eligible: false,
638+
},
639+
{
640+
state: "settled",
641+
overrides: { settledOverride: "settled" as const },
642+
eligible: false,
643+
},
644+
{
645+
state: "expired snooze",
646+
overrides: { snoozedUntil: "2026-03-09T10:30:00.000Z" },
647+
eligible: true,
648+
},
649+
{
650+
state: "snoozed but waiting on input",
651+
overrides: { snoozedUntil: "2026-03-09T14:00:00.000Z", hasPendingUserInput: true },
652+
eligible: true,
653+
},
654+
])("respects $state visibility when choosing a fallback", ({ overrides, eligible }) => {
655+
const deletedThread = makeThread({ id: ThreadId.make("deleted") });
656+
const candidate = makeThread({
657+
id: ThreadId.make("candidate"),
658+
createdAt: "2026-03-09T10:10:00.000Z",
659+
...overrides,
660+
});
661+
const olderVisibleThread = makeThread({ id: ThreadId.make("older-visible") });
662+
const otherProjectThread = makeThread({
663+
id: ThreadId.make("other-project"),
664+
projectId: ProjectId.make("project-2"),
665+
createdAt: "2026-03-09T10:15:00.000Z",
666+
});
667+
const input = {
668+
deletedThreadId: deletedThread.id,
669+
sortOrder: "created_at" as const,
670+
now: "2026-03-09T11:00:00.000Z",
671+
};
672+
673+
expect(
674+
getFallbackThreadIdAfterDelete({
675+
...input,
676+
threads: [deletedThread, candidate, olderVisibleThread, otherProjectThread],
677+
}),
678+
).toBe(eligible ? candidate.id : olderVisibleThread.id);
679+
expect(
680+
getFallbackThreadIdAfterDelete({
681+
...input,
682+
threads: [deletedThread, candidate, otherProjectThread],
683+
}),
684+
).toBe(eligible ? candidate.id : null);
685+
});
631686
});
632687

633688
describe("sortScopedProjectsForSidebar", () => {

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,14 @@ export function resolveThreadStatusPill(input: {
12111211
}
12121212

12131213
export function getFallbackThreadIdAfterDelete<
1214-
T extends Pick<Thread, "id" | "projectId" | "createdAt" | "updatedAt"> & ThreadSortInput,
1214+
T extends Pick<Thread, "id" | "projectId" | "createdAt" | "updatedAt" | "settledOverride"> &
1215+
ThreadSortInput &
1216+
ThreadSnoozeShell,
12151217
>(input: {
12161218
threads: readonly T[];
12171219
deletedThreadId: T["id"];
12181220
sortOrder: SidebarThreadSortOrder;
1221+
now: string;
12191222
deletedThreadIds?: ReadonlySet<T["id"]>;
12201223
}): T["id"] | null {
12211224
const { deletedThreadId, deletedThreadIds, sortOrder, threads } = input;
@@ -1230,7 +1233,9 @@ export function getFallbackThreadIdAfterDelete<
12301233
(thread) =>
12311234
thread.projectId === deletedThread.projectId &&
12321235
thread.id !== deletedThreadId &&
1233-
!deletedThreadIds?.has(thread.id),
1236+
!deletedThreadIds?.has(thread.id) &&
1237+
thread.settledOverride !== "settled" &&
1238+
!effectiveSnoozed(thread, { now: input.now }),
12341239
),
12351240
sortOrder,
12361241
)[0]?.id ?? null

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export function useThreadActions() {
554554
deletedThreadId: threadRef.threadId,
555555
deletedThreadIds,
556556
sortOrder: sidebarThreadSortOrder,
557+
now: new Date().toISOString(),
557558
});
558559
const deleteResult = await deleteThreadMutation({
559560
environmentId: threadRef.environmentId,

0 commit comments

Comments
 (0)