@@ -8,12 +8,8 @@ import {
88} from "@react-navigation/native" ;
99import { SymbolView } from "../../components/AppSymbol" ;
1010import { canCreateProjectInEnvironment } from "@t3tools/client-runtime/operations/projects" ;
11- import {
12- isScratchProject ,
13- resolveScratchEnvironmentId ,
14- } from "@t3tools/client-runtime/state/projects" ;
11+ import { isScratchProject } from "@t3tools/client-runtime/state/projects" ;
1512import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell" ;
16- import type { EnvironmentId } from "@t3tools/contracts" ;
1713import * as Cause from "effect/Cause" ;
1814import { AsyncResult } from "effect/unstable/reactivity" ;
1915import { useEffect , useRef , useState } from "react" ;
@@ -139,8 +135,7 @@ function NewTaskHeader(props: {
139135export function NewTaskRouteScreen ( { route } : StaticScreenProps < NewTaskRouteParams | undefined > ) {
140136 const projects = useProjects ( ) ;
141137 const [ searchText , setSearchText ] = useState ( "" ) ;
142- const { projectScopes, selectedEnvironmentId, chosenEnvironmentId, setProject } =
143- useNewTaskFlow ( ) ;
138+ const { projectScopes, selectedEnvironmentId, setProject } = useNewTaskFlow ( ) ;
144139 const { state : catalogState } = useWorkspaceState ( ) ;
145140 const navigation = useNavigation ( ) ;
146141 const isFocused = useIsFocused ( ) ;
@@ -160,8 +155,8 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
160155 const screenTitle = incomingShare ? "Start a task" : "Choose project" ;
161156 const projectEmptyState = deriveProjectEmptyState ( catalogState ) ;
162157 const serverConfigs = useServerConfigs ( ) ;
163- // The Scratch project is reached through the No project entry , never as a
164- // project row of its own.
158+ // Scratch projects are reached through the No project row , never as rows
159+ // of their own.
165160 const listScopes = projectScopes . filter (
166161 ( scope ) =>
167162 ! scope . projects . every ( ( project ) =>
@@ -182,35 +177,20 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
182177 reportFailure : false ,
183178 } ) ;
184179 // Threads without a project need a connected environment that offers them.
185- // The machine follows web's useScratchProject rule; when that leaves it
186- // open, every machine that offers one gets its own entry so the user picks .
180+ // The row starts on the selected environment when it has one, otherwise the
181+ // first that does; the draft page's machine picker moves it from there .
187182 const scratchEnvironments = connectedEnvironments . filter (
188183 ( environment ) =>
189184 canCreateProjectInEnvironment ( environment . connectionState ) &&
190185 serverConfigs . get ( environment . environmentId ) ?. scratchWorkspaceRoot !== undefined ,
191186 ) ;
192- const scratchEnvironmentId = resolveScratchEnvironmentId (
193- chosenEnvironmentId ,
194- scratchEnvironments . map ( ( environment ) => environment . environmentId ) ,
195- ) ;
196- const scratchChoices = (
197- scratchEnvironmentId === null
198- ? scratchEnvironments
199- : scratchEnvironments . filter (
200- ( environment ) => environment . environmentId === scratchEnvironmentId ,
201- )
202- ) . map ( ( environment ) => {
203- const machineLabel = connectedEnvironments . length > 1 ? environment . environmentLabel : null ;
204- return {
205- environmentId : environment . environmentId ,
206- startLabel : machineLabel
207- ? `Start without a project on ${ machineLabel } `
208- : "Start without a project" ,
209- rowLabel : machineLabel ? `No project on ${ machineLabel } ` : "No project" ,
210- rowSubtitle : machineLabel ? `On ${ machineLabel } ` : "Start a task without a project" ,
211- } ;
212- } ) ;
213- const canStartScratch = reservedDestinationProject === null ;
187+ const scratchEnvironment =
188+ scratchEnvironments . find (
189+ ( environment ) => environment . environmentId === selectedEnvironmentId ,
190+ ) ??
191+ scratchEnvironments [ 0 ] ??
192+ null ;
193+ const canStartScratch = scratchEnvironment !== null && reservedDestinationProject === null ;
214194 const scratchStartInFlightRef = useRef ( false ) ;
215195
216196 async function selectProject ( project : EnvironmentProject ) : Promise < void > {
@@ -245,8 +225,9 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
245225 ) ;
246226 }
247227
248- async function startScratch ( environmentId : EnvironmentId ) : Promise < void > {
249- if ( scratchStartInFlightRef . current ) return ;
228+ async function startScratch ( ) : Promise < void > {
229+ if ( ! scratchEnvironment || scratchStartInFlightRef . current ) return ;
230+ const environmentId = scratchEnvironment . environmentId ;
250231 scratchStartInFlightRef . current = true ;
251232 try {
252233 const result = await ensureScratch ( { environmentId, input : { } } ) ;
@@ -331,6 +312,55 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
331312 : { } ) ,
332313 } }
333314 >
315+ { canStartScratch && listScopes . length > 0 ? (
316+ Platform . OS === "android" ? (
317+ < View collapsable = { false } className = "overflow-hidden rounded-[28px] bg-card" >
318+ < MaterialListRow
319+ title = "No project"
320+ subtitle = "Start a task without a project"
321+ onPress = { ( ) => void startScratch ( ) }
322+ leading = {
323+ < SymbolView
324+ name = "text.bubble"
325+ size = { 22 }
326+ tintColorClassName = "accent-icon-muted"
327+ type = "monochrome"
328+ />
329+ }
330+ />
331+ </ View >
332+ ) : (
333+ < View collapsable = { false } className = "overflow-hidden rounded-[24px] bg-card" >
334+ < Pressable
335+ accessibilityRole = "button"
336+ accessibilityLabel = "No project"
337+ onPress = { ( ) => void startScratch ( ) }
338+ className = "flex-row items-center gap-3 bg-card px-4 py-3.5"
339+ >
340+ < View className = "h-7 w-7 items-center justify-center" >
341+ < SymbolView
342+ name = "text.bubble"
343+ size = { 18 }
344+ tintColorClassName = "accent-icon-muted"
345+ type = "monochrome"
346+ />
347+ </ View >
348+ < View className = "min-w-0 flex-1" >
349+ < Text className = "text-base font-t3-bold leading-snug" > No project</ Text >
350+ < Text className = "text-xs leading-snug text-foreground-muted" numberOfLines = { 1 } >
351+ Start a task without a project
352+ </ Text >
353+ </ View >
354+ < SymbolView
355+ name = "chevron.right"
356+ size = { 14 }
357+ tintColorClassName = "accent-chevron"
358+ type = "monochrome"
359+ />
360+ </ Pressable >
361+ </ View >
362+ )
363+ ) : null }
334364 { listScopes . length === 0 ? (
335365 < View
336366 collapsable = { false }
@@ -359,16 +389,13 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
359389 : navigation . navigate ( "ConnectionsNew" )
360390 }
361391 />
362- { canStartScratch
363- ? scratchChoices . map ( ( choice ) => (
364- < MaterialButton
365- key = { choice . environmentId }
366- label = { choice . startLabel }
367- tone = "secondary"
368- onPress = { ( ) => void startScratch ( choice . environmentId ) }
369- />
370- ) )
371- : null }
392+ { canStartScratch ? (
393+ < MaterialButton
394+ label = "Start without a project"
395+ tone = "secondary"
396+ onPress = { ( ) => void startScratch ( ) }
397+ />
398+ ) : null }
372399 </ >
373400 ) : ! catalogState . hasReadyEnvironment ? (
374401 < Pressable
@@ -389,19 +416,16 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
389416 Add new project
390417 </ Text >
391418 </ Pressable >
392- { canStartScratch
393- ? scratchChoices . map ( ( choice ) => (
394- < Pressable
395- key = { choice . environmentId }
396- className = "rounded-full bg-subtle px-4 py-2.5 active:opacity-70"
397- onPress = { ( ) => void startScratch ( choice . environmentId ) }
398- >
399- < Text className = "text-sm font-t3-bold text-foreground" >
400- { choice . startLabel }
401- </ Text >
402- </ Pressable >
403- ) )
404- : null }
419+ { canStartScratch ? (
420+ < Pressable
421+ className = "rounded-full bg-subtle px-4 py-2.5 active:opacity-70"
422+ onPress = { ( ) => void startScratch ( ) }
423+ >
424+ < Text className = "text-sm font-t3-bold text-foreground" >
425+ Start without a project
426+ </ Text >
427+ </ Pressable >
428+ ) : null }
405429 </ >
406430 ) }
407431 </ View >
@@ -502,68 +526,6 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
502526 } ) }
503527 </ View >
504528 ) }
505- { canStartScratch && scratchChoices . length > 0 && listScopes . length > 0 ? (
506- Platform . OS === "android" ? (
507- < View collapsable = { false } className = "overflow-hidden rounded-[28px] bg-card" >
508- { scratchChoices . map ( ( choice ) => (
509- < MaterialListRow
510- key = { choice . environmentId }
511- title = "No project"
512- subtitle = { choice . rowSubtitle }
513- onPress = { ( ) => void startScratch ( choice . environmentId ) }
514- leading = {
515- < SymbolView
516- name = "text.bubble"
517- size = { 22 }
518- tintColorClassName = "accent-icon-muted"
519- type = "monochrome"
520- />
521- }
522- />
523- ) ) }
524- </ View >
525- ) : (
526- < View collapsable = { false } className = "overflow-hidden rounded-[24px] bg-card" >
527- { scratchChoices . map ( ( choice , choiceIndex ) => (
528- < View
529- key = { choice . environmentId }
530- className = { cn ( choiceIndex > 0 && "border-t border-border-subtle" ) }
531- >
532- < Pressable
533- accessibilityRole = "button"
534- accessibilityLabel = { choice . rowLabel }
535- onPress = { ( ) => void startScratch ( choice . environmentId ) }
536- className = "flex-row items-center gap-3 bg-card px-4 py-3.5"
537- >
538- < View className = "h-7 w-7 items-center justify-center" >
539- < SymbolView
540- name = "text.bubble"
541- size = { 18 }
542- tintColorClassName = "accent-icon-muted"
543- type = "monochrome"
544- />
545- </ View >
546- < View className = "min-w-0 flex-1" >
547- < Text className = "text-base font-t3-bold leading-snug" > No project</ Text >
548- < Text
549- className = "text-xs leading-snug text-foreground-muted"
550- numberOfLines = { 1 }
551- >
552- { choice . rowSubtitle }
553- </ Text >
554- </ View >
555- < SymbolView
556- name = "chevron.right"
557- size = { 14 }
558- tintColorClassName = "accent-chevron"
559- type = "monochrome"
560- />
561- </ Pressable >
562- </ View >
563- ) ) }
564- </ View >
565- )
566- ) : null }
567529 </ ScrollView >
568530 </ MaterialScreenContent >
569531 </ View >
0 commit comments