@@ -29,7 +29,7 @@ import {
2929import { CommandId , type EnvironmentId , ProjectId } from "@t3tools/contracts" ;
3030import { StackActions , useNavigation } from "@react-navigation/native" ;
3131import { SymbolView } from "../../components/AppSymbol" ;
32- import { useCallback , useEffect , useMemo , useState , type ReactNode } from "react" ;
32+ import { useCallback , useEffect , useMemo , useRef , useState , type ReactNode } from "react" ;
3333import { ActivityIndicator , Alert , Pressable , ScrollView , View } from "react-native" ;
3434import { useSafeAreaInsets } from "react-native-safe-area-context" ;
3535import * as Arr from "effect/Array" ;
@@ -55,6 +55,7 @@ import {
5555 useRemoteEnvironmentRuntime ,
5656 useSavedRemoteConnections ,
5757} from "../../state/use-remote-environment-registry" ;
58+ import { resolveAddProjectEnvironment } from "./AddProjectScreen.logic" ;
5859
5960interface EnvironmentOption {
6061 readonly environmentId : EnvironmentId ;
@@ -236,10 +237,13 @@ function ProjectPathInput(props: {
236237}
237238
238239function useBrowsePathInput ( environment : EnvironmentOption | null ) {
240+ const environmentId = environment ?. environmentId ?? null ;
241+ const environmentBaseDirectory = environment ?. baseDirectory ?? null ;
239242 const [ pathInput , commitPathInput ] = useState ( ( ) =>
240- getAddProjectInitialQuery ( environment ?. baseDirectory ) ,
243+ getAddProjectInitialQuery ( environmentBaseDirectory ) ,
241244 ) ;
242- const environmentRuntime = useRemoteEnvironmentRuntime ( environment ?. environmentId ?? null ) ;
245+ const previousEnvironmentIdRef = useRef ( environmentId ) ;
246+ const environmentRuntime = useRemoteEnvironmentRuntime ( environmentId ) ;
243247 const loadBrowsePath = useAtomQueryRunner ( filesystemEnvironment . browse , {
244248 reportFailure : false ,
245249 reportDefect : false ,
@@ -277,10 +281,11 @@ function useBrowsePathInput(environment: EnvironmentOption | null) {
277281 ) ;
278282
279283 useEffect ( ( ) => {
280- if ( environment ) {
281- setPathInput ( getAddProjectInitialQuery ( environment . baseDirectory ) ) ;
284+ if ( environmentId !== null && environmentId !== previousEnvironmentIdRef . current ) {
285+ previousEnvironmentIdRef . current = environmentId ;
286+ setPathInput ( getAddProjectInitialQuery ( environmentBaseDirectory ) ) ;
282287 }
283- } , [ environment , setPathInput ] ) ;
288+ } , [ environmentBaseDirectory , environmentId , setPathInput ] ) ;
284289
285290 useEffect (
286291 ( ) => ( ) => {
@@ -583,17 +588,7 @@ function useEnvironmentFromParam(
583588) : EnvironmentOption | null {
584589 const environmentOptions = useEnvironmentOptions ( ) ;
585590 const environmentId = stringParam ( environmentIdParam ) as EnvironmentId | null ;
586- return (
587- environmentOptions . find (
588- ( environment ) =>
589- environment . environmentId === environmentId &&
590- canCreateProjectInEnvironment ( environment . connectionState ) ,
591- ) ??
592- environmentOptions . find ( ( environment ) =>
593- canCreateProjectInEnvironment ( environment . connectionState ) ,
594- ) ??
595- null
596- ) ;
591+ return resolveAddProjectEnvironment ( environmentOptions , environmentId ) ;
597592}
598593
599594export function AddProjectRepositoryScreen ( props : {
@@ -657,26 +652,32 @@ export function AddProjectRepositoryScreen(props: {
657652 return (
658653 < AddProjectShell >
659654 { error ? < ErrorBanner message = { error } /> : null }
660- < TextInput
661- className = "h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
662- value = { repositoryInput }
663- onChangeText = { setRepositoryInput }
664- autoCapitalize = "none"
665- autoCorrect = { false }
666- placeholder = {
667- source === "url"
668- ? "https://github.com/org/repo.git"
669- : addProjectRemoteSourcePathHint ( source )
670- }
671- returnKeyType = "next"
672- onSubmitEditing = { ( ) => void lookupRepository ( ) }
673- />
674- < PrimaryActionButton
675- label = { source === "url" ? "Continue" : "Lookup repository" }
676- disabled = { isSubmitting || repositoryInput . trim ( ) . length === 0 }
677- onPress = { ( ) => void lookupRepository ( ) }
678- loading = { isSubmitting }
679- />
655+ { environment ? (
656+ < >
657+ < TextInput
658+ className = "h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
659+ value = { repositoryInput }
660+ onChangeText = { setRepositoryInput }
661+ autoCapitalize = "none"
662+ autoCorrect = { false }
663+ placeholder = {
664+ source === "url"
665+ ? "https://github.com/org/repo.git"
666+ : addProjectRemoteSourcePathHint ( source )
667+ }
668+ returnKeyType = "next"
669+ onSubmitEditing = { ( ) => void lookupRepository ( ) }
670+ />
671+ < PrimaryActionButton
672+ label = { source === "url" ? "Continue" : "Lookup repository" }
673+ disabled = { isSubmitting || repositoryInput . trim ( ) . length === 0 }
674+ onPress = { ( ) => void lookupRepository ( ) }
675+ loading = { isSubmitting }
676+ />
677+ </ >
678+ ) : (
679+ < EmptyEnvironmentState />
680+ ) }
680681 </ AddProjectShell >
681682 ) ;
682683}
0 commit comments