diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index 879ccb14f0..86d6eeff05 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -362,7 +362,15 @@ export function HomeScreen(props: HomeScreenProps) { () => v2ProjectScopeKey === null ? null - : (v2ScopeProjects.find((project) => project.key === v2ProjectScopeKey) ?? null), + : (v2ScopeProjects.find( + (scope) => + scope.key === v2ProjectScopeKey || + scope.projectRefs.some( + (projectRef) => + scopedProjectKey(projectRef.environmentId, projectRef.projectId) === + v2ProjectScopeKey, + ), + ) ?? null), [v2ProjectScopeKey, v2ScopeProjects], ); const v2ScopedProjectKeys = useMemo( @@ -370,8 +378,8 @@ export function HomeScreen(props: HomeScreenProps) { v2ScopedProjectGroup === null ? null : new Set( - v2ScopedProjectGroup.projects.map((project) => - scopedProjectKey(project.environmentId, project.id), + v2ScopedProjectGroup.projectRefs.map((projectRef) => + scopedProjectKey(projectRef.environmentId, projectRef.projectId), ), ), [v2ScopedProjectGroup], diff --git a/apps/mobile/src/features/home/homeThreadList.test.ts b/apps/mobile/src/features/home/homeThreadList.test.ts index 884fe7d5da..2a29be19cf 100644 --- a/apps/mobile/src/features/home/homeThreadList.test.ts +++ b/apps/mobile/src/features/home/homeThreadList.test.ts @@ -250,6 +250,53 @@ describe("buildHomeThreadGroups", () => { ).toEqual([validProject.id, invalidProject.id]); }); + it("uses the freshest member when a grouped scope has no activity", () => { + const localEnvironmentId = EnvironmentId.make("environment-local"); + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const olderMember = makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-older-member"), + title: "t3code", + updatedAt: "2026-06-01T00:00:00.000Z", + repositoryIdentity, + }); + const newerMember = makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-newer-member"), + title: "t3code", + updatedAt: "2026-06-03T00:00:00.000Z", + repositoryIdentity, + }); + const otherProject = makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-other"), + title: "other", + updatedAt: "2026-06-02T00:00:00.000Z", + }); + const scopes = buildHomeProjectScopes({ + projects: [olderMember, newerMember, otherProject], + environmentId: null, + projectGroupingMode: "repository", + }); + + expect( + sortHomeProjectScopes({ + scopes, + threads: [], + pendingTasks: [], + projectSortOrder: "updated_at", + })[0]?.key, + ).toBe(scopes.find((scope) => scope.projects.length === 2)?.key); + }); + it("does not merge unrelated repositories that share a title", () => { const environmentId = EnvironmentId.make("environment-1"); const projects = ["one", "two"].map((name) => diff --git a/apps/mobile/src/features/home/homeThreadList.ts b/apps/mobile/src/features/home/homeThreadList.ts index 3e8fc663cc..375d3ea980 100644 --- a/apps/mobile/src/features/home/homeThreadList.ts +++ b/apps/mobile/src/features/home/homeThreadList.ts @@ -167,7 +167,11 @@ export function sortHomeProjectScopes(input: { (scope: HomeProjectScope) => ({ timestamp: latestActivityByScope.get(scope.key) ?? - getProjectSortTimestamp(scope.representative, input.projectSortOrder), + Math.max( + ...scope.projects.map((project) => + getProjectSortTimestamp(project, input.projectSortOrder), + ), + ), title: scope.title, key: scope.key, }),