From 542ce60b9e4bdce9058f404656a38788fccb8ce2 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sat, 4 Jul 2026 14:24:13 -0700 Subject: [PATCH] Show the quick new-thread button on multi-machine project groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of hiding the plus on aggregated groups, target the member that owns the group's newest thread — the machine the user last worked on. The draft's computer picker covers switching from there. Synthetic pending-project groups still hide the button (placeholder shells). Co-Authored-By: Claude Fable 5 --- apps/mobile/src/features/home/HomeScreen.tsx | 7 +-- .../src/features/home/homeListItems.test.ts | 2 + .../src/features/home/homeThreadList.test.ts | 49 +++++++++++++++++++ .../src/features/home/homeThreadList.ts | 31 ++++++++++++ .../threads/ThreadNavigationSidebar.tsx | 7 +-- .../features/threads/thread-list-items.tsx | 14 ++++-- 6 files changed, 97 insertions(+), 13 deletions(-) diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index 999cec2d66..d3b069176f 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -253,11 +253,8 @@ export function HomeScreen(props: HomeScreenProps) { // target project, and `pending-project:` groups hold a placeholder // built from queued-task metadata rather than a real project shell, // so the quick new-thread button is single-real-project only. - onNewThread={ - item.group.projects.length === 1 && !item.group.key.startsWith("pending-project:") - ? props.onNewThreadInProject - : undefined - } + newThreadTarget={item.group.newThreadTarget} + onNewThread={props.onNewThreadInProject} project={item.group.representative} threadCount={item.group.threads.length + item.group.pendingTasks.length} title={item.group.title} diff --git a/apps/mobile/src/features/home/homeListItems.test.ts b/apps/mobile/src/features/home/homeListItems.test.ts index c964453a6d..36e98ef129 100644 --- a/apps/mobile/src/features/home/homeListItems.test.ts +++ b/apps/mobile/src/features/home/homeListItems.test.ts @@ -70,6 +70,7 @@ function makeGroup(key: string, threadCount: number): HomeThreadGroup { // All threads inside the recency window, so the baseline stays at the // initial page size and the pagination expectations below hold. recentThreads: threads, + newThreadTarget: project, }; } @@ -171,6 +172,7 @@ describe("buildHomeListLayout", () => { pendingTasks: [], threads, recentThreads: threads.slice(0, 3), + newThreadTarget: project, }; const collapsedToRecent = buildHomeListLayout({ diff --git a/apps/mobile/src/features/home/homeThreadList.test.ts b/apps/mobile/src/features/home/homeThreadList.test.ts index 864591f754..8f13000b9e 100644 --- a/apps/mobile/src/features/home/homeThreadList.test.ts +++ b/apps/mobile/src/features/home/homeThreadList.test.ts @@ -314,4 +314,53 @@ describe("buildHomeThreadGroups", () => { group?.threads.map((thread) => thread.id), ); }); + + it("targets quick new threads at the group member with the newest thread", () => { + const laptopEnv = EnvironmentId.make("environment-laptop"); + const desktopEnv = EnvironmentId.make("environment-desktop"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const laptopProject = makeProject({ + environmentId: laptopEnv, + id: ProjectId.make("project-laptop"), + title: "t3code", + repositoryIdentity, + }); + const desktopProject = makeProject({ + environmentId: desktopEnv, + id: ProjectId.make("project-desktop"), + title: "t3code", + repositoryIdentity, + }); + const threads = [ + makeThread({ + environmentId: laptopEnv, + id: ThreadId.make("thread-laptop"), + projectId: laptopProject.id, + title: "Older laptop thread", + updatedAt: "2026-06-27T00:00:00.000Z", + }), + makeThread({ + environmentId: desktopEnv, + id: ThreadId.make("thread-desktop"), + projectId: desktopProject.id, + title: "Newest desktop thread", + updatedAt: "2026-06-28T00:00:00.000Z", + }), + ]; + + // Aggregated into one group by repository; the quick new-thread target + // must follow the newest thread (desktop), not the arbitrary first member. + const groups = buildGroups([laptopProject, desktopProject], threads); + expect(groups).toHaveLength(1); + expect(groups[0]?.projects).toHaveLength(2); + expect(groups[0]?.newThreadTarget?.environmentId).toBe(desktopEnv); + expect(groups[0]?.newThreadTarget?.id).toBe(desktopProject.id); + }); }); diff --git a/apps/mobile/src/features/home/homeThreadList.ts b/apps/mobile/src/features/home/homeThreadList.ts index 4e3516331b..cada956d8b 100644 --- a/apps/mobile/src/features/home/homeThreadList.ts +++ b/apps/mobile/src/features/home/homeThreadList.ts @@ -14,6 +14,7 @@ import type { SidebarThreadSortOrder, } from "@t3tools/contracts"; import * as Arr from "effect/Array"; +import * as Option from "effect/Option"; import * as Order from "effect/Order"; import { scopedProjectKey } from "../../lib/scopedEntities"; @@ -39,6 +40,15 @@ export interface HomeThreadGroup { readonly threads: ReadonlyArray; /** Subset shown by default: threads from the last few days, or the most recent few. */ readonly recentThreads: ReadonlyArray; + /** + * Where a quick "new thread in this project" should land. For aggregated + * groups (same repo on several machines) this is the member that owns the + * group's most recent thread — the machine the user last worked on — rather + * than the arbitrary first member; the draft's computer picker covers + * switching from there. Null only for synthetic pending-project groups, + * whose single "project" is a placeholder built from queued-task metadata. + */ + readonly newThreadTarget: EnvironmentProject | null; } interface MutableHomeThreadGroup { @@ -205,6 +215,24 @@ export function buildHomeThreadGroups(input: { ? selectRecentThreads(sortedThreads, input.threadSortOrder, now) : sortedThreads; + // Sorted newest-first, so the first thread whose project is a group member + // marks the machine the user last worked on. + const lastActiveProject = Arr.findFirst(sortedThreads, (thread) => + group.projects.some( + (project) => + project.environmentId === thread.environmentId && project.id === thread.projectId, + ), + ).pipe( + Option.flatMap((thread) => + Arr.findFirst( + group.projects, + (project) => + project.environmentId === thread.environmentId && project.id === thread.projectId, + ), + ), + Option.getOrNull, + ); + result.push({ key: group.key, title, @@ -213,6 +241,9 @@ export function buildHomeThreadGroups(input: { pendingTasks: matchingPendingTasks, threads: sortedThreads, recentThreads, + newThreadTarget: group.key.startsWith("pending-project:") + ? null + : (lastActiveProject ?? representative), }); } diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index 2d7e732bde..c639bd60f5 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -420,11 +420,8 @@ function ThreadNavigationSidebarPane( // Same gating as the compact Home list: aggregated groups have no // single target project, and pending-project groups hold a // placeholder shell rather than a real project. - onNewThread={ - item.group.projects.length === 1 && !item.group.key.startsWith("pending-project:") - ? props.onNewThreadInProject - : undefined - } + newThreadTarget={item.group.newThreadTarget} + onNewThread={props.onNewThreadInProject} project={item.group.representative} threadCount={item.group.threads.length + item.group.pendingTasks.length} title={item.group.title} diff --git a/apps/mobile/src/features/threads/thread-list-items.tsx b/apps/mobile/src/features/threads/thread-list-items.tsx index 47108d6b36..654be473b9 100644 --- a/apps/mobile/src/features/threads/thread-list-items.tsx +++ b/apps/mobile/src/features/threads/thread-list-items.tsx @@ -43,16 +43,24 @@ export const ThreadListGroupHeader = memo(function ThreadListGroupHeader(props: readonly isFirst: boolean; readonly groupKey: string; readonly onGroupAction: (key: string, action: HomeGroupDisplayAction) => void; + /** Project a quick new thread should target; null hides the button. */ + readonly newThreadTarget?: EnvironmentProject | null; readonly onNewThread?: (project: EnvironmentProject) => void; }) { const iconMutedColor = useThemeColor("--color-icon-muted"); - const { groupKey, onGroupAction, onNewThread, project } = props; + const { groupKey, onGroupAction, onNewThread } = props; + const newThreadTarget = props.newThreadTarget ?? null; const compact = props.variant === "compact"; const handleToggle = useCallback( () => onGroupAction(groupKey, "toggle-collapsed"), [groupKey, onGroupAction], ); - const handleNewThread = useCallback(() => onNewThread?.(project), [onNewThread, project]); + const handleNewThread = useCallback(() => { + if (newThreadTarget) { + onNewThread?.(newThreadTarget); + } + }, [newThreadTarget, onNewThread]); + const showNewThreadButton = onNewThread !== undefined && newThreadTarget !== null; // The new-thread button is a SIBLING of the collapse toggle, not a child: // nested touchables are unreachable to VoiceOver/TalkBack (the parent @@ -111,7 +119,7 @@ export const ThreadListGroupHeader = memo(function ThreadListGroupHeader(props: {props.threadCount} - {onNewThread ? ( + {showNewThreadButton ? (