Skip to content

Commit 2a2e0d4

Browse files
fix(mobile): a draft whose project is gone keeps its text through the project picker
Opening an Unsent draft whose stamped project no longer exists sent the user to "Choose project", but picking a project opened a fresh, empty draft: the route resolution treated "draft gone" and "project gone" alike. The resolver now reports `pickProject` with the draft id when only the project is gone. The draft screen hands that id to the picker, which retargets the draft to the chosen project and opens it, so the composer shows the saved text and attachments. Backing out of the picker leaves the draft untouched; a draft that is truly gone still gets a fresh one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1075196 commit 2a2e0d4

4 files changed

Lines changed: 47 additions & 13 deletions

File tree

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,15 @@ export function NewTaskDraftScreen(props: {
275275
),
276276
);
277277
// A route naming a draft that is gone, or whose project is gone, also
278-
// returns to the picker.
279-
const isRouteDraftMissing =
280-
props.draftId !== undefined && flow.missingRouteDraftId === props.draftId;
278+
// returns to the picker; a draft that survives goes along with it.
279+
const unopenableRouteDraftKind =
280+
props.draftId !== undefined && flow.unopenableRouteDraft?.draftId === props.draftId
281+
? flow.unopenableRouteDraft.kind
282+
: null;
283+
const pickerDraftId = unopenableRouteDraftKind === "pickProject" ? props.draftId : undefined;
281284
const isProjectPickerReturnActive =
282-
(isReturningToProjectPicker && !requestedInitialProjectAvailable) || isRouteDraftMissing;
285+
(isReturningToProjectPicker && !requestedInitialProjectAvailable) ||
286+
unopenableRouteDraftKind !== null;
283287
const isIncomingShareAwaitingServerConfig = Boolean(
284288
incomingShare?.attachments.some((attachment) => attachment.type === "file") &&
285289
selectedEnvironmentServerConfig === null,
@@ -382,14 +386,18 @@ export function NewTaskDraftScreen(props: {
382386
// Wait for usePreventRemove to disable before replacing, or the transfer guard swallows the fallback.
383387
const frame = requestAnimationFrame(() => {
384388
navigation.dispatch(
385-
StackActions.replace("NewTaskProject", { incomingShareId: props.incomingShareId }),
389+
StackActions.replace("NewTaskProject", {
390+
incomingShareId: props.incomingShareId,
391+
draftId: pickerDraftId,
392+
}),
386393
);
387394
});
388395
return () => cancelAnimationFrame(frame);
389396
}, [
390397
isProjectPickerReturnActive,
391398
isReturningToProjectPicker,
392399
navigation,
400+
pickerDraftId,
393401
props.incomingShareId,
394402
requestedInitialProjectAvailable,
395403
]);

‎apps/mobile/src/features/threads/NewTaskRouteScreen.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ProjectFavicon } from "../../components/ProjectFavicon";
2929
import { useProjects, useServerConfigs } from "../../state/entities";
3030
import { projectEnvironment } from "../../state/projects";
3131
import { useAtomCommand } from "../../state/use-atom-command";
32+
import { retargetNewTaskDraft } from "../../state/use-composer-drafts";
3233
import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry";
3334
import type { WorkspaceState } from "../../state/workspaceModel";
3435
import { useWorkspaceState } from "../../state/workspace";
@@ -40,6 +41,8 @@ import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail"
4041

4142
type NewTaskRouteParams = {
4243
readonly incomingShareId?: string | string[];
44+
/** An existing draft whose project is gone; the chosen project takes it over. */
45+
readonly draftId?: string | string[];
4346
readonly prompt?: string | string[];
4447
readonly repo?: string | string[];
4548
readonly pr?: string | string[];
@@ -162,6 +165,9 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
162165
? route.params.incomingShareId[0]
163166
: route.params?.incomingShareId;
164167
const incomingShare = routeShareId ? getShare(routeShareId) : null;
168+
const routeDraftId = Array.isArray(route.params?.draftId)
169+
? route.params.draftId[0]
170+
: route.params?.draftId;
165171
const incomingShareSubtitle = incomingShare
166172
? incomingShare.attachments.length === 0
167173
? "Choose a project for what you shared"
@@ -231,17 +237,25 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
231237
: navigation.getParent();
232238
const rootState = root?.getState();
233239
const threadRoute = rootState?.routes[rootState.index - 1];
234-
if (isDraftThreadRoute(threadRoute)) {
240+
if (routeDraftId === undefined && isDraftThreadRoute(threadRoute)) {
235241
setProject(project);
236242
root?.goBack();
237243
return;
238244
}
245+
// Restamp only on choice, so backing out leaves the draft as it was.
246+
if (routeDraftId !== undefined) {
247+
retargetNewTaskDraft(routeDraftId, {
248+
environmentId: project.environmentId,
249+
projectId: project.id,
250+
});
251+
}
239252
selectDetail({
240253
name: "Thread",
241254
params: {
242255
draft: {
243256
environmentId: String(project.environmentId),
244257
projectId: String(project.id),
258+
draftId: routeDraftId,
245259
incomingShareId: incomingShare?.id,
246260
},
247261
},

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,14 @@ type NewTaskFlowContextValue = {
175175
/** The flow's project, read when a continuation resumes after an await. */
176176
readonly getSelectedProjectKey: () => string | null;
177177
/**
178-
* The draft id of the route this flow serves when that draft, or its
179-
* project, is gone. Only the topmost draft route is served, so a screen
180-
* compares this with its own draft id.
178+
* The route this flow serves when its draft cannot open: the draft is gone
179+
* (`missing`) or only its project is (`pickProject`). Only the topmost draft
180+
* route is served, so a screen compares `draftId` with its own draft id.
181181
*/
182-
readonly missingRouteDraftId: string | null;
182+
readonly unopenableRouteDraft: {
183+
readonly draftId: string;
184+
readonly kind: "missing" | "pickProject";
185+
} | null;
183186
readonly selectEnvironment: (environmentId: EnvironmentId) => void;
184187
readonly switchEnvironment: (environmentId: EnvironmentId) => Promise<boolean>;
185188
readonly switchingToEnvironmentId: EnvironmentId | null;
@@ -879,8 +882,11 @@ export function NewTaskFlowProvider(
879882
providerGroups,
880883
setProject,
881884
getSelectedProjectKey: () => readFlow().projectKey,
882-
missingRouteDraftId:
883-
routeDraftResolution.kind === "missing" ? (props.routeDraftId ?? null) : null,
885+
unopenableRouteDraft:
886+
props.routeDraftId !== undefined &&
887+
(routeDraftResolution.kind === "missing" || routeDraftResolution.kind === "pickProject")
888+
? { draftId: props.routeDraftId, kind: routeDraftResolution.kind }
889+
: null,
884890
selectEnvironment,
885891
switchEnvironment,
886892
switchingToEnvironmentId,

‎apps/mobile/src/features/threads/new-task-flow-state.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export type RouteDraftResolution =
7575
| { readonly kind: "none" }
7676
| { readonly kind: "pending" }
7777
| { readonly kind: "missing" }
78+
/** The draft survives but its project is gone: pick another for it. */
79+
| { readonly kind: "pickProject"; readonly draftId: string }
7880
| { readonly kind: "open"; readonly flow: NewTaskFlowState };
7981

8082
export function resolveRouteDraft(input: {
@@ -101,7 +103,11 @@ export function resolveRouteDraft(input: {
101103
const loaded = input.projects.some(
102104
(project) => project.environmentId === stamp.environmentId && project.id === stamp.projectId,
103105
);
104-
if (!loaded) return input.stampedEnvironmentLoading ? { kind: "pending" } : { kind: "missing" };
106+
if (!loaded) {
107+
return input.stampedEnvironmentLoading
108+
? { kind: "pending" }
109+
: { kind: "pickProject", draftId: routeDraftId };
110+
}
105111
return {
106112
kind: "open",
107113
flow: {

0 commit comments

Comments
 (0)