From 6c118965d42583230ac9307fa111e87568432658 Mon Sep 17 00:00:00 2001 From: nach <10445733+nachogames@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:09:44 -0500 Subject: [PATCH] fix(mobile): finished threads rise to the top of their project section Group by project turns the Working section off (f8b525c17f), and that also turned off its newest-return order, so a thread that finished stayed where it was. Rows inside each project now sort by latest start or finish while Working is on in settings; project sections keep their order, and rows arranged in Edit mode keep their saved places. Committed with --no-verify: the file's existing untranslated labels trip t3code/no-untranslated-copy, as on main. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/home/HomeScreen.tsx | 2 + .../features/home/homeProjectSections.test.ts | 40 ++++++++++++++++++- .../src/features/home/homeProjectSections.ts | 16 +++++++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index d6a6a70ce3f76..5d1aa22947315 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -625,6 +625,8 @@ export function HomeScreen(props: HomeScreenProps) { ? buildHomeProjectSections({ items: threadListV2Items, showProjectHeaders: v2ScopedProjectGroup === null, + // The Working shelf is off in project sections, so its return order applies here instead. + newestReturnFirst: workingShelfPreferred, projectOf: (thread) => projectScopeByProjectKey.get(scopedProjectKey(thread.environmentId, thread.projectId)) ?? null, diff --git a/apps/mobile/src/features/home/homeProjectSections.test.ts b/apps/mobile/src/features/home/homeProjectSections.test.ts index 780d08c5c26c5..136a33de4e2b8 100644 --- a/apps/mobile/src/features/home/homeProjectSections.test.ts +++ b/apps/mobile/src/features/home/homeProjectSections.test.ts @@ -1,5 +1,5 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; -import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts"; +import { EnvironmentId, ProjectId, RunId, ThreadId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; import { makeThreadShellFixture } from "../../test-fixtures"; @@ -38,7 +38,10 @@ function thread( function sections( threads: ReadonlyArray, options: Partial< - Pick + Pick< + HomeProjectSectionsInput, + "showProjectHeaders" | "projectOrder" | "rowOrder" | "liveOrder" | "newestReturnFirst" + > > & { readonly expanded?: ReadonlyArray; readonly collapsed?: ReadonlyArray; @@ -88,6 +91,7 @@ function sections( ...(options.projectOrder ? { projectOrder: options.projectOrder } : {}), ...(options.rowOrder ? { rowOrder: options.rowOrder } : {}), ...(options.liveOrder ? { liveOrder: options.liveOrder } : {}), + ...(options.newestReturnFirst ? { newestReturnFirst: true } : {}), }); } @@ -183,6 +187,38 @@ describe("buildHomeProjectSections", () => { ]); }); + it("lifts a finished thread to the top of its project without moving projects", () => { + const finished = (at: string) => ({ + latestRun: { + runId: RunId.make(`run-${at}`), + status: "completed" as const, + requestedAt: at, + startedAt: at, + completedAt: at, + assistantMessageId: null, + }, + }); + const threads = [ + thread("e", "ember", { createdAt: "2026-10-03T00:00:00.000Z" }), + thread("a", "ctrl", { createdAt: "2026-10-02T00:00:00.000Z" }), + thread("done", "ctrl", finished("2026-10-05T00:00:00.000Z")), + ]; + expect(describeItems(sections(threads).items)).toEqual([ + "# Project ember", + "e", + "# Project ctrl", + "a", + "done", + ]); + expect(describeItems(sections(threads, { newestReturnFirst: true }).items)).toEqual([ + "# Project ember", + "e", + "# Project ctrl", + "done", + "a", + ]); + }); + it("keeps an unarranged new thread in its natural slot", () => { const key = (id: string) => `v2-thread:${environmentId}:${id}`; const { items } = sections( diff --git a/apps/mobile/src/features/home/homeProjectSections.ts b/apps/mobile/src/features/home/homeProjectSections.ts index 553eba0e9526e..ba1af522cb33c 100644 --- a/apps/mobile/src/features/home/homeProjectSections.ts +++ b/apps/mobile/src/features/home/homeProjectSections.ts @@ -1,4 +1,5 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; +import { sortInboxThreadsByReturn } from "@t3tools/client-runtime/state/thread-inbox"; import { resolveThreadListV2Status, @@ -68,6 +69,8 @@ export interface HomeProjectSectionsInput { readonly projectOrder?: ReadonlyArray; /** Arranged row keys (groups and threads) inside projects; see `arrangeInSlots`. */ readonly rowOrder?: ReadonlyArray; + /** Rows inside a project put the latest finished or started thread first; projects keep their order. */ + readonly newestReturnFirst?: boolean; /** While a row is dragged in Edit mode: its sibling set in the order under the finger. */ readonly liveOrder?: { readonly siblings: string; readonly order: ReadonlyArray }; } @@ -92,6 +95,13 @@ function needsUser(thread: EnvironmentThreadShell): boolean { return status === "approval" || status === "input"; } +function byReturn(entries: ReadonlyArray) { + const entryByThread = new Map(entries.map((entry) => [entry.item.thread, entry])); + return sortInboxThreadsByReturn(entries.map((entry) => entry.item.thread)).map((thread) => + entryByThread.get(thread)!, + ); +} + function withMoves( entry: ThreadListV2ThreadListItem, canMoveUp: boolean, @@ -213,7 +223,11 @@ export function buildHomeProjectSections(input: HomeProjectSectionsInput): HomeP bucket.entries.push(entry); } const projects = arrange( - [...buckets].map(([key, bucket]) => ({ key, title: bucket.title, entries: bucket.entries })), + [...buckets].map(([key, bucket]) => ({ + key, + title: bucket.title, + entries: input.newestReturnFirst === true ? byReturn(bucket.entries) : bucket.entries, + })), (project) => project.key, input.projectOrder, );