Skip to content

Commit 1191747

Browse files
t3dotggclaude
andcommitted
Derive newThreadTarget from the full thread history, not search matches
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent b21d872 commit 1191747

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

‎apps/mobile/src/features/home/homeThreadList.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,4 +743,48 @@ describe("buildHomeThreadGroups", () => {
743743
expect(groups[0]?.newThreadTarget?.environmentId).toBe(desktopEnv);
744744
expect(groups[0]?.newThreadTarget?.id).toBe(desktopProject.id);
745745
});
746+
747+
it("keeps the quick new-thread target when search hides the newest thread", () => {
748+
const laptopProject = makeProject({
749+
environmentId: EnvironmentId.make("environment-laptop"),
750+
id: ProjectId.make("project-laptop"),
751+
title: "t3code",
752+
repositoryIdentity: {
753+
canonicalKey: "github.com/pingdotgg/t3code",
754+
locator: {
755+
source: "git-remote",
756+
remoteName: "origin",
757+
remoteUrl: "[email protected]:pingdotgg/t3code.git",
758+
},
759+
},
760+
});
761+
const desktopProject = makeProject({
762+
...laptopProject,
763+
environmentId: EnvironmentId.make("environment-desktop"),
764+
id: ProjectId.make("project-desktop"),
765+
});
766+
const laptopThread = makeThread({
767+
environmentId: laptopProject.environmentId,
768+
id: ThreadId.make("thread-laptop"),
769+
projectId: laptopProject.id,
770+
title: "Older laptop thread",
771+
updatedAt: "2026-06-27T00:00:00.000Z",
772+
});
773+
const desktopThread = makeThread({
774+
environmentId: desktopProject.environmentId,
775+
id: ThreadId.make("thread-desktop"),
776+
projectId: desktopProject.id,
777+
title: "Newest desktop thread",
778+
updatedAt: "2026-06-28T00:00:00.000Z",
779+
});
780+
const projects = [laptopProject, desktopProject];
781+
const threads = [laptopThread, desktopThread];
782+
783+
const groups = buildGroups(projects, threads);
784+
const searchGroups = buildGroups(projects, threads, { searchQuery: "laptop" });
785+
786+
expect(groups[0]?.newThreadTarget).toEqual(desktopProject);
787+
expect(searchGroups[0]?.threads).toEqual([laptopThread]);
788+
expect(searchGroups[0]?.newThreadTarget).toEqual(desktopProject);
789+
});
746790
});

‎apps/mobile/src/features/home/homeThreadList.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,22 @@ export function buildHomeThreadGroups(input: {
327327
continue;
328328
}
329329

330-
const sortedThreads = sortThreads(matchingThreads, input.threadSortOrder);
330+
const sortedGroupThreads = sortThreads(group.threads, input.threadSortOrder);
331+
const matchingThreadSet = groupMatches ? null : new Set(matchingThreads);
332+
const sortedThreads =
333+
matchingThreadSet === null
334+
? sortedGroupThreads
335+
: sortedGroupThreads.filter((thread) => matchingThreadSet.has(thread));
331336
// An active search should reach the full history, so the recency window
332337
// only trims the default (no-query) view.
333338
const recentThreads =
334339
query.length === 0
335340
? selectRecentThreads(sortedThreads, input.threadSortOrder, now)
336341
: sortedThreads;
337342

338-
// A stale project id still resolves to the canonical member with the same
339-
// environment/path, so quick creation follows the machine with the newest activity.
340-
const lastActiveProject = Arr.head(sortedThreads).pipe(
343+
// Use the full history so search does not change the target machine.
344+
// Resolve stale project IDs to the canonical member at the same environment/path.
345+
const lastActiveProject = Arr.head(sortedGroupThreads).pipe(
341346
Option.flatMap((thread) =>
342347
Arr.findFirst(
343348
input.projects,

0 commit comments

Comments
 (0)