@@ -29,6 +29,7 @@ import { ProjectFavicon } from "../../components/ProjectFavicon";
2929import { useProjects , useServerConfigs } from "../../state/entities" ;
3030import { projectEnvironment } from "../../state/projects" ;
3131import { useAtomCommand } from "../../state/use-atom-command" ;
32+ import { retargetSavedNewTaskDraft } from "../../state/use-composer-drafts" ;
3233import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry" ;
3334import type { WorkspaceState } from "../../state/workspaceModel" ;
3435import { useWorkspaceState } from "../../state/workspace" ;
@@ -44,6 +45,8 @@ import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspace
4445
4546type NewTaskRouteParams = {
4647 readonly incomingShareId ?: string | string [ ] ;
48+ /** An existing draft whose project is gone; the chosen project takes it over. */
49+ readonly draftId ?: string | string [ ] ;
4750 readonly prompt ?: string | string [ ] ;
4851 readonly repo ?: string | string [ ] ;
4952 readonly pr ?: string | string [ ] ;
@@ -164,6 +167,9 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
164167 ? route . params . incomingShareId [ 0 ]
165168 : route . params ?. incomingShareId ;
166169 const incomingShare = routeShareId ? getShare ( routeShareId ) : null ;
170+ const routeDraftId = Array . isArray ( route . params ?. draftId )
171+ ? route . params . draftId [ 0 ]
172+ : route . params ?. draftId ;
167173 const incomingShareSubtitle = incomingShare
168174 ? incomingShare . attachments . length === 0
169175 ? "Choose a project for what you shared"
@@ -228,17 +234,34 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
228234 : navigation . getParent ( ) ;
229235 const rootState = root ?. getState ( ) ;
230236 const threadRoute = rootState ?. routes [ rootState . index - 1 ] ;
231- if ( isDraftThreadRoute ( threadRoute ) ) {
237+ if ( routeDraftId === undefined && isDraftThreadRoute ( threadRoute ) ) {
232238 setProject ( project ) ;
233239 root ?. goBack ( ) ;
234240 return ;
235241 }
242+ // Restamp only on choice, so backing out leaves the draft as it was.
243+ const retargeted =
244+ routeDraftId === undefined
245+ ? false
246+ : await retargetSavedNewTaskDraft ( routeDraftId , {
247+ environmentId : project . environmentId ,
248+ projectId : project . id ,
249+ } ) . then (
250+ ( found ) => found ,
251+ ( ) => null ,
252+ ) ;
253+ if ( retargeted === null ) {
254+ Dialog . alert ( "Could not change project" , "Saved drafts could not be loaded. Try again." ) ;
255+ return ;
256+ }
257+ const draftId = retargeted ? routeDraftId : undefined ;
236258 selectDetail ( {
237259 name : "Thread" ,
238260 params : {
239261 draft : {
240262 environmentId : String ( project . environmentId ) ,
241263 projectId : String ( project . id ) ,
264+ draftId,
242265 incomingShareId : incomingShare ?. id ,
243266 } ,
244267 } ,
0 commit comments