Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/mobile/src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 38 additions & 2 deletions apps/mobile/src/features/home/homeProjectSections.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -38,7 +38,10 @@ function thread(
function sections(
threads: ReadonlyArray<EnvironmentThreadShell>,
options: Partial<
Pick<HomeProjectSectionsInput, "showProjectHeaders" | "projectOrder" | "rowOrder" | "liveOrder">
Pick<
HomeProjectSectionsInput,
"showProjectHeaders" | "projectOrder" | "rowOrder" | "liveOrder" | "newestReturnFirst"
>
> & {
readonly expanded?: ReadonlyArray<string>;
readonly collapsed?: ReadonlyArray<string>;
Expand Down Expand Up @@ -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 } : {}),
});
}

Expand Down Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion apps/mobile/src/features/home/homeProjectSections.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import { sortInboxThreadsByReturn } from "@t3tools/client-runtime/state/thread-inbox";

import {
resolveThreadListV2Status,
Expand Down Expand Up @@ -68,6 +69,8 @@ export interface HomeProjectSectionsInput {
readonly projectOrder?: ReadonlyArray<string>;
/** Arranged row keys (groups and threads) inside projects; see `arrangeInSlots`. */
readonly rowOrder?: ReadonlyArray<string>;
/** 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<string> };
}
Expand All @@ -92,6 +95,13 @@ function needsUser(thread: EnvironmentThreadShell): boolean {
return status === "approval" || status === "input";
}

function byReturn(entries: ReadonlyArray<ThreadListV2ThreadListItem>) {
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,
Expand Down Expand Up @@ -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,
);
Expand Down
Loading