From a95e3cff411f879537ed57e9403ff6f98097ef90 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 01:16:51 +0000 Subject: [PATCH 1/2] test(mobile): share drafts start in the last project (#38756) Fails on main: resolveDraftProjectSelection ignores Use last project and the remembered project, so a share with two projects always opens the picker. Co-Authored-By: Claude Opus 5.5 --- .../threads/new-task-project-selection.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/mobile/src/features/threads/new-task-project-selection.test.ts b/apps/mobile/src/features/threads/new-task-project-selection.test.ts index 82533a3c91e74..61d8864e55a1f 100644 --- a/apps/mobile/src/features/threads/new-task-project-selection.test.ts +++ b/apps/mobile/src/features/threads/new-task-project-selection.test.ts @@ -200,6 +200,20 @@ describe("resolveDraftProjectSelection", () => { }), ).toEqual({ kind: "pick" }); }); + + it("starts a share draft in the last project when Use last project is on", () => { + const scopes = [makeScope([projects[0]!]), makeScope([projects[1]!])]; + const shareDraft = { + incomingShareId: "share", + pickerClosed: false, + useLastProject: undefined, + lastProject: { environmentId: "environment", projectId: "t3code-2" }, + }; + expect(resolveDraftProjectSelection(null, projects, scopes, shareDraft)).toEqual({ + kind: "select", + project: projects[1], + }); + }); }); describe("newTaskDestination", () => { From c4d839408b569148db4c824861ae89655389c677 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 02:07:44 +0000 Subject: [PATCH 2/2] fix(mobile): shares into T3 Code start in the last project Fixes pingdotgg/t3code#38756 Co-Authored-By: Claude Opus 5.5 --- .../features/threads/NewTaskDraftScreen.tsx | 5 +++++ .../new-task-project-selection.test.ts | 10 ++++++++++ .../threads/new-task-project-selection.ts | 20 +++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx index d1230b01b7973..a7d32c8788c85 100644 --- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx +++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx @@ -98,6 +98,7 @@ import { newTaskFlowKey } from "./new-task-flow-state"; import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol"; import { ConnectionStatusDot } from "../connection/ConnectionStatusDot"; import { appAtomRegistry } from "../../state/atom-registry"; +import { mobilePreferencesAtom } from "../../state/preferences"; import { readEnvironmentScope, useEnvironmentScope } from "../../state/session"; @@ -473,6 +474,8 @@ export function NewTaskDraftScreen(props: { return; } + const preferences = appAtomRegistry.get(mobilePreferencesAtom); + const saved = AsyncResult.isSuccess(preferences) ? preferences.value : undefined; const selection = resolveDraftProjectSelection( selectedProjectKey, projects, @@ -480,6 +483,8 @@ export function NewTaskDraftScreen(props: { { incomingShareId: props.incomingShareId, pickerClosed: initialPickerRef.current === "open" && isFocused, + useLastProject: saved?.useLastProjectForNewThreads, + lastProject: saved?.lastThreadProject, }, ); if (selection.kind === "preserve") { diff --git a/apps/mobile/src/features/threads/new-task-project-selection.test.ts b/apps/mobile/src/features/threads/new-task-project-selection.test.ts index 61d8864e55a1f..3105158237d67 100644 --- a/apps/mobile/src/features/threads/new-task-project-selection.test.ts +++ b/apps/mobile/src/features/threads/new-task-project-selection.test.ts @@ -213,6 +213,16 @@ describe("resolveDraftProjectSelection", () => { kind: "select", project: projects[1], }); + expect( + resolveDraftProjectSelection(null, projects, scopes, { + ...shareDraft, + useLastProject: false, + }), + ).toEqual({ kind: "pick" }); + const archived = [projects[0]!, { ...projects[1]!, archivedAt: "2026-07-02T00:00:00.000Z" }]; + expect(resolveDraftProjectSelection(null, archived, scopes, shareDraft)).toEqual({ + kind: "pick", + }); }); }); diff --git a/apps/mobile/src/features/threads/new-task-project-selection.ts b/apps/mobile/src/features/threads/new-task-project-selection.ts index 2fa21eba1e234..58f7adcf27b64 100644 --- a/apps/mobile/src/features/threads/new-task-project-selection.ts +++ b/apps/mobile/src/features/threads/new-task-project-selection.ts @@ -138,6 +138,8 @@ export function resolveDraftProjectSelection( readonly incomingShareId: string | undefined; /** The draft's first project picker closed and the draft is showing again. */ readonly pickerClosed: boolean; + readonly useLastProject?: boolean | undefined; + readonly lastProject?: ProjectRef | undefined; }, ): DraftProjectSelectionResolution { const hasExplicitProjectSelection = @@ -153,8 +155,22 @@ export function resolveDraftProjectSelection( return { kind: "dismiss" }; } - const onlyScope = - draft.incomingShareId !== undefined && projectScopes.length === 1 ? projectScopes[0] : null; + if (draft.incomingShareId === undefined) { + return { kind: "pick" }; + } + const last = + draft.useLastProject === false + ? undefined + : projects.find( + (project) => + project.environmentId === draft.lastProject?.environmentId && + project.id === draft.lastProject.projectId && + project.archivedAt == null, + ); + if (last) { + return { kind: "select", project: last }; + } + const onlyScope = projectScopes.length === 1 ? projectScopes[0] : null; return onlyScope ? { kind: "select", project: onlyScope.representative } : { kind: "pick" }; }