@@ -7,11 +7,13 @@ import {
77 type StaticScreenProps ,
88} from "@react-navigation/native" ;
99import { SymbolView } from "../../components/AppSymbol" ;
10- import { canCreateProjectInEnvironment } from "@t3tools/client-runtime/operations/projects" ;
10+ import { availableScratchWorkspaceRoot } from "@t3tools/client-runtime/operations/projects" ;
1111import { isScratchProject } from "@t3tools/client-runtime/state/projects" ;
12+ import {
13+ isAtomCommandInterrupted ,
14+ squashAtomCommandFailure ,
15+ } from "@t3tools/client-runtime/state/runtime" ;
1216import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell" ;
13- import * as Cause from "effect/Cause" ;
14- import { AsyncResult } from "effect/unstable/reactivity" ;
1517import { useEffect , useRef , useState } from "react" ;
1618import { ActivityIndicator , Alert , Platform , Pressable , View } from "react-native" ;
1719import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -21,7 +23,7 @@ import { MaterialButton } from "../../components/MaterialButton";
2123import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView" ;
2224import { AppText as Text } from "../../components/AppText" ;
2325import { ProjectFavicon } from "../../components/ProjectFavicon" ;
24- import { useProjects , useServerConfigs , waitForProject } from "../../state/entities" ;
26+ import { useProjects , useServerConfigs } from "../../state/entities" ;
2527import { projectEnvironment } from "../../state/projects" ;
2628import { useAtomCommand } from "../../state/use-atom-command" ;
2729import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry" ;
@@ -173,16 +175,18 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
173175 ) ?? null )
174176 : null ;
175177 const { connectedEnvironments } = useRemoteConnectionStatus ( ) ;
176- const ensureScratch = useAtomCommand ( projectEnvironment . ensureScratch , {
178+ const openScratch = useAtomCommand ( projectEnvironment . openScratch , {
177179 reportFailure : false ,
178180 } ) ;
179181 // Threads without a project need a connected environment that offers them.
180182 // The row starts on the selected environment when it has one, otherwise the
181183 // first that does; the draft page's machine picker moves it from there.
182184 const scratchEnvironments = connectedEnvironments . filter (
183185 ( environment ) =>
184- canCreateProjectInEnvironment ( environment . connectionState ) &&
185- serverConfigs . get ( environment . environmentId ) ?. scratchWorkspaceRoot !== undefined ,
186+ availableScratchWorkspaceRoot (
187+ environment . connectionState ,
188+ serverConfigs . get ( environment . environmentId ) ,
189+ ) !== null ,
186190 ) ;
187191 const scratchEnvironment =
188192 scratchEnvironments . find (
@@ -230,26 +234,20 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
230234 const environmentId = scratchEnvironment . environmentId ;
231235 scratchStartInFlightRef . current = true ;
232236 try {
233- const result = await ensureScratch ( { environmentId, input : { } } ) ;
234- if ( AsyncResult . isFailure ( result ) ) {
235- const error = Cause . squash ( result . cause ) ;
236- Alert . alert (
237- "Could not start without a project" ,
238- error instanceof Error
239- ? error . message
240- : "The folder for threads without a project could not be created." ,
241- ) ;
242- return ;
243- }
244- const project = await waitForProject ( { environmentId, projectId : result . value . projectId } ) ;
245- if ( project === null ) {
246- Alert . alert (
247- "Could not start without a project" ,
248- "It has not reached this device yet. Pick No project from the list once it appears." ,
249- ) ;
237+ const result = await openScratch ( { environmentId, input : { } } ) ;
238+ if ( result . _tag === "Failure" ) {
239+ if ( ! isAtomCommandInterrupted ( result ) ) {
240+ const error = squashAtomCommandFailure ( result ) ;
241+ Alert . alert (
242+ "Could not start without a project" ,
243+ error instanceof Error
244+ ? error . message
245+ : "The folder for threads without a project could not be created." ,
246+ ) ;
247+ }
250248 return ;
251249 }
252- await selectProject ( project ) ;
250+ await selectProject ( result . value ) ;
253251 } finally {
254252 scratchStartInFlightRef . current = false ;
255253 }
0 commit comments