Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AddProjectScreen.tsx

1,475 lines50.3 KB

1import * as Dialog from "../../components/ui/Dialog";
2import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
3import { NavigationRow } from "../../components/ui/NavigationRow";
4import { SettingsScreen } from "../settings/components/SettingsScreen";
5import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
6import { Button } from "../../components/ui/Button";
7import {
8 addProjectRemoteSourceLabel,
9 addProjectRemoteSourcePathHint,
10 addProjectRemoteSourceProvider,
11 buildAddProjectRemoteSourceReadiness,
12 buildProjectCreateCommand,
13 canCreateProjectInEnvironment,
14 findExistingAddProject,
15 getAddProjectInitialQuery,
16 getCloneDestinationBrowsePath,
17 getCloneDestinationPath,
18 getCloneDirectoryName,
19 getDefaultCloneUrl,
20 getNewProjectPathPreview,
21 getNewProjectPublishTarget,
22 getNewProjectPublishTargets,
23 getNewProjectRepository,
24 normalizePastedCloneUrl,
25 parseAddProjectRemoteSource,
26 resolveAddProjectPath,
27 sortAddProjectProviderSources,
28 type AddProjectRemoteSource,
29} from "@t3tools/client-runtime/operations/projects";
30import {
31 connectionStatusText,
32 type EnvironmentConnectionPhase,
33} from "@t3tools/client-runtime/connection";
34import {
35 canPreloadBrowsePath,
36 createBrowseNavigationCoordinator,
37 filterFilesystemBrowseEntries,
38 getFilesystemBrowsePath,
39 resolveFilesystemReadAccess,
40} from "@t3tools/client-runtime/state/filesystem";
41import {
42 appendBrowsePathSegment,
43 inferProjectTitleFromPath,
44 isWindowsPlatform,
45} from "@t3tools/client-runtime/state/projects";
46import {
47 AuthOrchestrationOperateScope,
48 AuthSourceControlWriteScope,
49 AuthFilesystemReadScope,
50 CommandId,
51 type EnvironmentId,
52 type EnvironmentMachineKind,
53 ProjectId,
54 resolveEnvironmentMachineKind,
55 SourceControlProviderKind,
56} from "@t3tools/contracts";
57import { CommonActions, StackActions, useNavigation } from "@react-navigation/native";
58import { SymbolView } from "../../components/ui/AppSymbol";
59import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
60import { Platform, Pressable, View } from "react-native";
61import { useSafeAreaInsets } from "react-native-safe-area-context";
62import * as Arr from "effect/Array";
63import * as Cause from "effect/Cause";
64import * as Order from "effect/Order";
65import { AsyncResult } from "effect/reactivity";
66import { cn } from "../../lib/cn";
67import { useProjects, useServerConfigs, waitForProject } from "../../state/entities";
68import { filesystemEnvironment } from "../../state/filesystem";
69import { projectEnvironment } from "../../state/projects";
70import { useEnvironmentQuery } from "../../state/query";
71import { environmentSession, useEnvironmentScope, readEnvironmentScope } from "../../state/session";
72import { useEnvironmentPresentation } from "../../state/presentation";
73import { sourceControlEnvironment } from "../../state/sourceControl";
74import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
75import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
76import { ErrorBanner } from "../../components/ui/ErrorBanner";
77import { SourceControlIcon } from "./SourceControlIcon";
78import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
79import { ThemedSwitch } from "../../components/ui/ThemedSwitch";
80import { uuidv4 } from "../../lib/uuid";
81import { useAtomCommand } from "../../state/use-atom-command";
82import { useAtomQueryRunner } from "../../state/use-atom-query-runner";
83import {
84 useRemoteConnectionStatus,
85 useRemoteEnvironmentRuntime,
86 useSavedRemoteConnections,
87} from "../../state/use-remote-environment-registry";
88import { resolveAddProjectEnvironment } from "./AddProjectScreen.logic";
89import {
90 createNewTaskDraft,
91 setComposerDraftText,
92 waitForComposerDraftsLoaded,
93} from "../../state/use-composer-drafts";
94​
95interface EnvironmentOption {
96 readonly environmentId: EnvironmentId;
97 readonly label: string;
98 readonly platform: string;
99 readonly machine: EnvironmentMachineKind;
100 readonly baseDirectory: string | null;
101 readonly newProjectsRoot: string | null;
102 readonly connectionState: EnvironmentConnectionPhase;
103 readonly connectionError: string | null;
104 readonly connectionErrorTraceId: string | null;
105 readonly supportsCloneTracking: boolean;
107​
108const environmentOptionOrder = Order.mapInput(
109 Order.Struct({
110 label: Order.String,
111 }),
112 (environment: EnvironmentOption) => ({ label: environment.label }),
113);
114​
115function platformFromOs(os: string | null | undefined): string {
116 if (os === "windows") return "Win32";
117 if (os === "darwin") return "MacIntel";
118 if (os === "linux") return "Linux";
119 return "";
121​
122function errorMessage(error: unknown): string {
123 return error instanceof Error && error.message.trim().length > 0
124 ? error.message
125 : "An error occurred.";
127​
128function stringParam(value: string | string[] | undefined): string | null {
129 if (Array.isArray(value)) return value[0] ?? null;
130 return value ?? null;
132​
133function sourceFromParam(value: string | string[] | undefined): AddProjectRemoteSource {
134 return parseAddProjectRemoteSource(stringParam(value));
136​
137function SectionTitle(props: { readonly children: string }) {
138 return (
139 <Text
140 className={
141 Platform.OS === "android"
142 ? "px-4 text-sm font-t3-medium text-primary-text"
143 : "px-1 text-2xs font-t3-bold tracking-[0.7px] uppercase text-foreground-muted"
144 }
145 >
146 {props.children}
147 </Text>
148 );
150​
151function AddProjectShell(props: { readonly children: ReactNode; readonly title: string }) {
152 const insets = useSafeAreaInsets();
153​
154 return (
155 // collapsable={false} is load-bearing: if this wrapper is flattened, the
156 // ScrollView lands directly under RNSSafeAreaView and RNS's formSheet
157 // scroll-view frame correction mistakes this full-height wrapper for a
158 // "header" sibling, coercing the ScrollView to zero height (blank sheet
159 // as soon as the sheet re-lays-out, e.g. when the keyboard opens).
160 <SettingsScreen title={props.title}>
161 <ScrollView
162 keyboardShouldPersistTaps="handled"
163 contentInsetAdjustmentBehavior="automatic"
164 contentContainerStyle={{
165 paddingHorizontal: Platform.OS === "android" ? 16 : 20,
166 paddingTop: 16,
167 paddingBottom: Math.max(insets.bottom, 18) + 18,
168 gap: Platform.OS === "android" ? 16 : 10,
169 }}
170 >
171 {props.children}
172 </ScrollView>
173 </SettingsScreen>
174 );
176​
177function ListSection(props: { readonly children: ReactNode }) {
178 return (
179 <View
180 className={
181 Platform.OS === "android"
182 ? "overflow-hidden rounded-[28px] bg-grouped-card"
183 : "overflow-hidden rounded-[24px] bg-grouped-card"
184 }
185 >
186 {props.children}
187 </View>
188 );
190​
191function ListRow(props: {
192 readonly title: string;
193 readonly subtitle?: string | null;
194 readonly icon: ReactNode;
195 readonly disabled?: boolean;
196 readonly selected?: boolean;
197 readonly isFirst?: boolean;
198 readonly right?: ReactNode;
199 readonly onPress?: () => void;
200}) {
201 if (Platform.OS === "android") {
202 return (
203 <NavigationRow
204 className="bg-grouped-card"
205 title={props.title}
206 subtitle={props.subtitle}
207 leading={props.icon}
208 trailing={props.right}
209 disabled={props.disabled}
210 onPress={props.onPress}
211 accessibilityRole={props.selected !== undefined ? "radio" : "button"}
212 accessibilityState={props.selected !== undefined ? { checked: props.selected } : undefined}
213 />
214 );
215 }
216 return (
217 <Pressable
218 disabled={props.disabled}
219 onPress={props.onPress}
220 className={cn(
221 "bg-grouped-card px-3.5 py-2.5 active:opacity-70",
222 !props.isFirst && "border-t border-border-subtle",
223 props.disabled && "opacity-[0.45]",
224 )}
225 >
226 <View className="flex-row items-center gap-3">
227 <View
228 className={
229 props.selected
230 ? "h-7 w-7 items-center justify-center rounded-full bg-primary"
231 : "h-7 w-7 items-center justify-center"
232 }
233 >
234 {props.icon}
235 </View>
236 <View className="flex-1 gap-0.5">
237 <Text className="text-base leading-snug font-t3-bold">{props.title}</Text>
238 {props.subtitle ? (
239 <Text className="text-sm leading-snug text-foreground-muted" numberOfLines={2}>
240 {props.subtitle}
241 </Text>
242 ) : null}
243 </View>
244 {"right" in props ? (
245 props.right
246 ) : !props.disabled ? (
247 <SymbolView
248 name="chevron.right"
249 size={13}
250 tintColorClassName="accent-chevron"
251 type="monochrome"
252 />
253 ) : null}
254 </View>
255 </Pressable>
256 );
258​
259function PrimaryActionButton(props: {
260 readonly label: string;
261 readonly disabled?: boolean;
262 readonly loading?: boolean;
263 readonly onPress: () => void;
264}) {
265 if (Platform.OS === "android") return <Button {...props} tone="primary" fullWidth />;
266 return (
267 <Pressable
268 disabled={props.disabled}
269 onPress={props.onPress}
270 className="h-12 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"
271 >
272 {props.loading ? (
273 <AppActivityIndicator colorClassName={String("accent-primary-foreground")} />
274 ) : (
275 <Text className="text-base font-t3-bold text-primary-foreground">{props.label}</Text>
276 )}
277 </Pressable>
278 );
280​
281function ProjectPathInput(props: {
282 readonly value: string;
283 readonly onChangeText: (value: string) => void;
284 readonly onSubmit: () => void;
285}) {
286 return (
287 <TextInput
288 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
289 value={props.value}
290 onChangeText={props.onChangeText}
291 autoCapitalize="none"
292 autoCorrect={false}
293 placeholder="~/projects/my-app"
294 returnKeyType="done"
295 onSubmitEditing={props.onSubmit}
296 />
297 );
299​
300function useBrowsePathInput(environment: EnvironmentOption | null, pinnedDirectoryName = "") {
301 const environmentId = environment?.environmentId ?? null;
302 const environmentBaseDirectory = environment?.baseDirectory ?? null;
303 const clonePathCaseSensitive = !isWindowsPlatform(environment?.platform ?? "");
304 const [pathInput, commitPathInput] = useState(() =>
305 getCloneDestinationPath(
306 getAddProjectInitialQuery(environmentBaseDirectory),
307 pinnedDirectoryName,
308 ),
309 );
310 const previousEnvironmentIdRef = useRef(environmentId);
311 const environmentRuntime = useRemoteEnvironmentRuntime(environmentId);
312 const loadBrowsePath = useAtomQueryRunner(filesystemEnvironment.browse, {
313 reportFailure: false,
314 reportDefect: false,
315 });
316 const [browseNavigation] = useState(createBrowseNavigationCoordinator);
317 const [isBrowseNavigating, setIsBrowseNavigating] = useState(false);
318 const setPathInput = useCallback(
319 (path: string) => {
320 browseNavigation.invalidate();
321 setIsBrowseNavigating(false);
322 commitPathInput(path);
323 },
324 [browseNavigation],
325 );
326 const navigateToBrowsePath = useCallback(
327 async (input: {
328 readonly browseDirectoryPath: string;
329 readonly selectedDirectoryName?: string;
330 }) => {
331 const selectedDirectoryPath = input.selectedDirectoryName
332 ? appendBrowsePathSegment(input.browseDirectoryPath, input.selectedDirectoryName)
333 : input.browseDirectoryPath;
334 const nextPathInput =
335 pinnedDirectoryName && input.selectedDirectoryName
336 ? getCloneDestinationBrowsePath({
337 browseDirectoryPath: input.browseDirectoryPath,
338 selectedDirectoryName: input.selectedDirectoryName,
339 cloneDirectoryName: pinnedDirectoryName,
340 caseSensitive: clonePathCaseSensitive,
341 })
342 : getCloneDestinationPath(selectedDirectoryPath, pinnedDirectoryName);
343 setIsBrowseNavigating(true);
344 const committed = await browseNavigation.run(
345 async () => {
346 if (
347 environment &&
348 readEnvironmentScope(environment.environmentId, AuthFilesystemReadScope) &&
349 canPreloadBrowsePath(environmentRuntime?.connectionState)
350 ) {
351 await loadBrowsePath({
352 environmentId: environment.environmentId,
353 input: { partialPath: selectedDirectoryPath },
354 });
355 }
356 },
357 () => commitPathInput(nextPathInput),
358 );
359 if (committed) {
360 setIsBrowseNavigating(false);
361 }
362 return committed;
363 },
364 [
365 browseNavigation,
366 clonePathCaseSensitive,
367 environment,
368 environmentRuntime?.connectionState,
369 loadBrowsePath,
370 pinnedDirectoryName,
371 ],
372 );
373​
374 useEffect(() => {
375 if (environmentId !== null && environmentId !== previousEnvironmentIdRef.current) {
376 previousEnvironmentIdRef.current = environmentId;
377 setPathInput(
378 getCloneDestinationPath(
379 getAddProjectInitialQuery(environmentBaseDirectory),
380 pinnedDirectoryName,
381 ),
382 );
383 }
384 }, [environmentBaseDirectory, environmentId, pinnedDirectoryName, setPathInput]);
385​
386 useEffect(
387 () => () => {
388 browseNavigation.invalidate();
389 },
390 [browseNavigation],
391 );
392​
393 return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath };
395​
396function useEnvironmentOptions(): ReadonlyArray<EnvironmentOption> {
397 const serverConfigByEnvironmentId = useServerConfigs();
398 const { savedConnectionsById } = useSavedRemoteConnections();
399 const { connectedEnvironments } = useRemoteConnectionStatus();
400​
401 return useMemo<ReadonlyArray<EnvironmentOption>>(() => {
402 const runtimeByEnvironmentId = new Map(
403 connectedEnvironments.map((environment) => [environment.environmentId, environment] as const),
404 );
405 const options = Object.values(savedConnectionsById).map((connection) => {
406 const config = serverConfigByEnvironmentId.get(connection.environmentId);
407 const runtime = runtimeByEnvironmentId.get(connection.environmentId);
408 return {
409 environmentId: connection.environmentId,
410 label: connection.environmentLabel,
411 platform: platformFromOs(config?.environment.platform.os ?? null),
412 machine: resolveEnvironmentMachineKind(config ?? null),
413 baseDirectory: config?.settings.addProjectBaseDirectory ?? null,
414 newProjectsRoot: config?.newProjectsRoot ?? null,
415 connectionState: runtime?.connectionState ?? "available",
416 connectionError: runtime?.connectionError ?? null,
417 connectionErrorTraceId: runtime?.connectionErrorTraceId ?? null,
418 supportsCloneTracking: config?.environment.capabilities.projectCloneTracking === true,
419 };
420 });
421 return Arr.sort(
422 options.filter((environment) => canCreateProjectInEnvironment(environment.connectionState)),
423 environmentOptionOrder,
424 );
425 }, [connectedEnvironments, savedConnectionsById, serverConfigByEnvironmentId]);
427​
428function useSelectedEnvironment(): {
429 readonly environmentOptions: ReadonlyArray<EnvironmentOption>;
430 readonly selectedEnvironment: EnvironmentOption | null;
431 readonly setSelectedEnvironmentId: (environmentId: EnvironmentId) => void;
432} {
433 const [selectedEnvironmentId, setSelectedEnvironmentId] = useState<EnvironmentId | null>(null);
434 const environmentOptions = useEnvironmentOptions();
435 const selectedEnvironment =
436 environmentOptions.find(
437 (environment) =>
438 environment.environmentId === selectedEnvironmentId &&
439 canCreateProjectInEnvironment(environment.connectionState),
440 ) ??
441 environmentOptions.find((environment) =>
442 canCreateProjectInEnvironment(environment.connectionState),
443 ) ??
444 null;
445​
446 return {
447 environmentOptions,
448 selectedEnvironment,
449 setSelectedEnvironmentId,
450 };
452​
453function EmptyEnvironmentState() {
454 const navigation = useNavigation();
455​
456 return (
457 <View className="items-center gap-3 rounded-2xl bg-grouped-card px-5 py-8">
458 <Text className="text-center text-lg font-t3-bold">Environment unavailable</Text>
459 <Text className="text-center text-sm leading-normal text-foreground-muted">
460 Start or reconnect an environment before adding a project.
461 </Text>
462 <Pressable
463 onPress={() => navigation.dispatch(StackActions.replace("ConnectionsNew"))}
464 className="mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
465 >
466 <Text className="text-sm font-t3-bold text-primary-foreground">Add environment</Text>
467 </Pressable>
468 </View>
469 );
471​
472function SourceControlRow(props: {
473 readonly source: AddProjectRemoteSource;
474 readonly selectedEnvironmentId: EnvironmentId;
475 readonly ready: boolean;
476 readonly hint: string;
477 readonly isFirst: boolean;
478}) {
479 const navigation = useNavigation();
480 const title =
481 props.source === "url" ? "Git URL" : `${addProjectRemoteSourceLabel(props.source)} repository`;
482 const subtitle =
483 props.source === "url"
484 ? "Clone from a remote URL"
485 : `Clone ${addProjectRemoteSourceLabel(props.source)} ${props.hint}`;
486 const icon =
487 props.source === "url" ? (
488 <SymbolView
489 name="link"
490 size={Platform.OS === "android" ? 24 : 17}
491 tintColorClassName="accent-icon"
492 type="monochrome"
493 />
494 ) : (
495 <SourceControlIcon
496 kind={sourceControlClients.get(props.source).icon}
497 size={Platform.OS === "android" ? 24 : 18}
498 colorClassName="accent-icon"
499 />
500 );
501​
502 if (!props.ready) {
503 return (
504 <ListRow title={title} subtitle={props.hint} icon={icon} disabled isFirst={props.isFirst} />
505 );
506 }
507​
508 return (
509 <ListRow
510 title={title}
511 subtitle={subtitle}
512 icon={icon}
513 isFirst={props.isFirst}
514 onPress={() =>
515 navigation.dispatch(
516 StackActions.push("AddProjectRepository", {
517 environmentId: props.selectedEnvironmentId,
518 source: props.source,
519 }),
520 )
521 }
522 />
523 );
525​
526export function AddProjectSourceScreen() {
527 const navigation = useNavigation();
528 const { environmentOptions, selectedEnvironment, setSelectedEnvironmentId } =
529 useSelectedEnvironment();
530 const canWriteSourceControl = useEnvironmentScope(
531 selectedEnvironment?.environmentId ?? null,
532 AuthSourceControlWriteScope,
533 );
534 const canCreateProject = useEnvironmentScope(
535 selectedEnvironment?.environmentId ?? null,
536 AuthOrchestrationOperateScope,
537 );
538 const canCloneProject = canWriteSourceControl && canCreateProject;
539 const discoveryState = useEnvironmentQuery(
540 selectedEnvironment === null
541 ? null
542 : sourceControlEnvironment.discovery({
543 environmentId: selectedEnvironment.environmentId,
544 input: {},
545 }),
546 );
547 const readiness = useMemo(
548 () => buildAddProjectRemoteSourceReadiness(discoveryState.data),
549 [discoveryState.data],
550 );
551​
552 return (
553 <AddProjectShell title="Add project">
554 {selectedEnvironment === null ? <EmptyEnvironmentState /> : null}
555​
556 {environmentOptions.length > 1 ? (
557 <>
558 <SectionTitle>Environments</SectionTitle>
559 <ListSection>
560 {environmentOptions.map((environment, index) => (
561 <ListRow
562 key={environment.environmentId}
563 title={environment.label}
564 subtitle={
565 canCreateProjectInEnvironment(environment.connectionState)
566 ? undefined
567 : connectionStatusText({
568 phase: environment.connectionState,
569 error: environment.connectionError,
570 traceId: environment.connectionErrorTraceId,
571 })
572 }
573 icon={
574 <EnvironmentMachineSymbol
575 kind={environment.machine}
576 size={Platform.OS === "android" ? 24 : 17}
577 tintColorClassName="accent-icon"
578 />
579 }
580 selected={environment.environmentId === selectedEnvironment?.environmentId}
581 disabled={!canCreateProjectInEnvironment(environment.connectionState)}
582 isFirst={index === 0}
583 right={
584 environment.environmentId === selectedEnvironment?.environmentId ? (
585 <SymbolView
586 name="checkmark"
587 size={Platform.OS === "android" ? 20 : 14}
588 tintColorClassName="accent-icon"
589 type="monochrome"
590 />
591 ) : null
592 }
593 onPress={() => setSelectedEnvironmentId(environment.environmentId)}
594 />
595 ))}
596 </ListSection>
597 </>
598 ) : null}
599​
600 {selectedEnvironment ? (
601 <>
602 <ListSection>
603 {selectedEnvironment.newProjectsRoot !== null ? (
604 <ListRow
605 title="New project"
606 subtitle="Start a new Git repository from a name"
607 icon={
608 <SymbolView
609 name="plus"
610 size={Platform.OS === "android" ? 24 : 17}
611 tintColorClassName="accent-icon"
612 type="monochrome"
613 />
614 }
615 isFirst
616 onPress={() =>
617 navigation.dispatch(
618 StackActions.push("AddProjectNew", {
619 environmentId: selectedEnvironment.environmentId,
620 }),
621 )
622 }
623 />
624 ) : null}
625 <ListRow
626 title="Local folder"
627 subtitle={
628 canCreateProject
629 ? "Browse a folder on disk"
630 : "This connection cannot add projects."
631 }
632 icon={
633 <SymbolView
634 name="folder.badge.plus"
635 size={Platform.OS === "android" ? 24 : 17}
636 tintColorClassName="accent-icon"
637 type="monochrome"
638 />
639 }
640 isFirst={selectedEnvironment.newProjectsRoot === null}
641 disabled={!canCreateProject}
642 onPress={() =>
643 navigation.dispatch(
644 StackActions.push("AddProjectLocal", {
645 environmentId: selectedEnvironment.environmentId,
646 }),
647 )
648 }
649 />
650 {(["url", ...sortAddProjectProviderSources(readiness)] as AddProjectRemoteSource[]).map(
651 (candidate) => (
652 <SourceControlRow
653 key={candidate}
654 source={candidate}
655 selectedEnvironmentId={selectedEnvironment.environmentId}
656 ready={canCloneProject && readiness(candidate).ready}
657 hint={
658 !canCloneProject
659 ? "This connection cannot clone projects."
660 : readiness(candidate).ready
661 ? addProjectRemoteSourcePathHint(candidate)
662 : (readiness(candidate).hint ?? "")
663 }
664 isFirst={false}
665 />
666 ),
667 )}
668 </ListSection>
669 {discoveryState.isPending ? (
670 <AppActivityIndicator colorClassName="accent-icon-muted" />
671 ) : null}
672 </>
673 ) : null}
674 </AddProjectShell>
675 );
677​
678function openNewTaskDraft(
679 navigation: { dispatch: (action: ReturnType<typeof CommonActions.reset>) => void },
680 params: {
681 environmentId: EnvironmentId;
682 projectId: ProjectId;
683 title: string;
684 cloning?: "1";
685 draftId?: string;
686 },
687) {
688 navigation.dispatch(
689 CommonActions.reset({ index: 0, routes: [{ name: "NewTaskDraft", params }] }),
690 );
692​
693async function draftWithPrompt(
694 environmentId: EnvironmentId,
695 projectId: ProjectId,
696 prompt: string,
697): Promise<string> {
698 await waitForComposerDraftsLoaded();
699 const draftId = createNewTaskDraft({ environmentId, projectId });
700 setComposerDraftText(draftId, prompt);
701 return draftId;
703​
704function useCreateProject(environment: EnvironmentOption | null) {
705 const navigation = useNavigation();
706 const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
707 const projects = useProjects();
708​
709 return useCallback(
710 async (workspaceRoot: string) => {
711 if (
712 !environment ||
713 !canCreateProjectInEnvironment(environment.connectionState) ||
714 !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope)
715 ) {
716 Dialog.alert(
717 "Project not added",
718 `This connection cannot add projects right now. Any existing files remain at ${workspaceRoot}.`,
719 );
720 return;
721 }
722​
723 const existing = findExistingAddProject({
724 projects,
725 environmentId: environment.environmentId,
726 path: workspaceRoot,
727 });
728 if (existing) {
729 Dialog.alert("Project already exists", existing.title);
730 navigation.dispatch(
731 CommonActions.reset({
732 index: 0,
733 routes: [
734 {
735 name: "NewTaskDraft",
736 params: {
737 environmentId: existing.environmentId,
738 projectId: existing.id,
739 title: existing.title,
740 },
741 },
742 ],
743 }),
744 );
745 return;
746 }
747​
748 const projectId = ProjectId.make(uuidv4());
749 const command = buildProjectCreateCommand({
750 commandId: CommandId.make(uuidv4()),
751 projectId,
752 workspaceRoot,
753 });
754 const result = await createProject({
755 environmentId: environment.environmentId,
756 input: command,
757 });
758 if (AsyncResult.isFailure(result)) {
759 return result;
760 }
761 navigation.dispatch(
762 CommonActions.reset({
763 index: 0,
764 routes: [
765 {
766 name: "NewTaskDraft",
767 params: {
768 environmentId: environment.environmentId,
769 projectId,
770 title: inferProjectTitleFromPath(workspaceRoot),
771 },
772 },
773 ],
774 }),
775 );
776 return result;
777 },
778 [createProject, environment, projects, navigation],
779 );
781​
782function useEnvironmentFromParam(
783 environmentIdParam: string | string[] | undefined,
784): EnvironmentOption | null {
785 const environmentOptions = useEnvironmentOptions();
786 const environmentId = stringParam(environmentIdParam) as EnvironmentId | null;
787 return resolveAddProjectEnvironment(environmentOptions, environmentId);
789​
790export function AddProjectRepositoryScreen(props: {
791 readonly environmentId?: string | string[];
792 readonly source?: string | string[];
793}) {
794 const lookupRepositoryQuery = useAtomQueryRunner(sourceControlEnvironment.repository, {
795 reportFailure: false,
796 });
797 const navigation = useNavigation();
798 const environment = useEnvironmentFromParam(props.environmentId);
799 const source = sourceFromParam(props.source);
800 const [repositoryInput, setRepositoryInput] = useState("");
801 const [isSubmitting, setIsSubmitting] = useState(false);
802 const [error, setError] = useState<string | null>(null);
803​
804 const lookupRepository = useCallback(async () => {
805 if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return;
806 setError(null);
807 setIsSubmitting(true);
808 const provider = addProjectRemoteSourceProvider(source);
809 if (!provider) {
810 const remoteUrl = normalizePastedCloneUrl(repositoryInput);
811 navigation.dispatch(
812 StackActions.push("AddProjectDestination", {
813 environmentId: environment.environmentId,
814 source,
815 remoteUrl,
816 repositoryTitle: remoteUrl,
817 repositoryName: getCloneDirectoryName(remoteUrl),
818 }),
819 );
820 setIsSubmitting(false);
821 return;
822 }
823​
824 const result = await lookupRepositoryQuery({
825 environmentId: environment.environmentId,
826 input: {
827 provider,
828 repository: repositoryInput.trim(),
829 },
830 });
831 if (AsyncResult.isFailure(result)) {
832 setError(errorMessage(Cause.squash(result.cause)));
833 } else {
834 const repository = result.value;
835 navigation.dispatch(
836 StackActions.push("AddProjectDestination", {
837 environmentId: environment.environmentId,
838 source,
839 remoteUrl: getDefaultCloneUrl(repository),
840 repositoryTitle: repository.nameWithOwner,
841 repositoryName: getCloneDirectoryName(repository.nameWithOwner),
842 }),
843 );
844 }
845 setIsSubmitting(false);
846 }, [environment, isSubmitting, lookupRepositoryQuery, repositoryInput, navigation, source]);
847​
848 return (
849 <AddProjectShell title={source === "url" ? "Git URL" : addProjectRemoteSourceLabel(source)}>
850 {error ? <ErrorBanner message={error} /> : null}
851 {environment ? (
852 <>
853 <TextInput
854 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
855 value={repositoryInput}
856 onChangeText={setRepositoryInput}
857 autoCapitalize="none"
858 autoCorrect={false}
859 placeholder={
860 source === "url"
861 ? "https://github.com/org/repo.git"
862 : addProjectRemoteSourcePathHint(source)
863 }
864 returnKeyType="next"
865 onSubmitEditing={() => void lookupRepository()}
866 />
867 <PrimaryActionButton
868 label={source === "url" ? "Continue" : "Lookup repository"}
869 disabled={isSubmitting || repositoryInput.trim().length === 0}
870 onPress={() => void lookupRepository()}
871 loading={isSubmitting}
872 />
873 </>
874 ) : (
875 <EmptyEnvironmentState />
876 )}
877 </AddProjectShell>
878 );
880​
881function FolderBrowser(props: {
882 readonly environment: EnvironmentOption;
883 readonly pathInput: string;
884 readonly setPathInput: (path: string) => void;
885 readonly navigateToBrowsePath: (input: {
886 readonly browseDirectoryPath: string;
887 readonly selectedDirectoryName?: string;
888 }) => Promise<boolean>;
889 readonly pinnedDirectoryName?: string;
890}) {
891 const browsePath = useMemo(
892 () => getFilesystemBrowsePath(props.pathInput, props.environment.platform),
893 [props.environment.platform, props.pathInput],
894 );
895 const browseInput = useMemo(
896 () => (browsePath.directoryPath.length > 0 ? { partialPath: browsePath.directoryPath } : null),
897 [browsePath.directoryPath],
898 );
899 const fileAccessSession = useEnvironmentQuery(
900 environmentSession.sessionStateAtom(props.environment.environmentId),
901 );
902 const fileEnvironment = useEnvironmentPresentation(props.environment.environmentId);
903 const fileAccess = resolveFilesystemReadAccess({
904 isCatalogReady: fileEnvironment.isReady,
905 connection: fileEnvironment.presentation?.connection ?? null,
906 session: fileAccessSession.data,
907 sessionError: fileAccessSession.error,
908 });
909 const { canReadFiles } = fileAccess;
910 const browseState = useEnvironmentQuery(
911 !canReadFiles || browseInput === null
912 ? null
913 : filesystemEnvironment.browse({
914 environmentId: props.environment.environmentId,
915 input: browseInput,
916 }),
917 );
918 const pinnedDirectoryName = props.pinnedDirectoryName ?? "";
919 const pinnedDirectoryMatches = isWindowsPlatform(props.environment.platform)
920 ? browsePath.filterQuery.toLowerCase() === pinnedDirectoryName.toLowerCase()
921 : browsePath.filterQuery === pinnedDirectoryName;
922 const browseFilterQuery = pinnedDirectoryMatches ? "" : browsePath.filterQuery;
923 const { visibleEntries: visibleBrowseEntries } = useMemo(
924 () => filterFilesystemBrowseEntries(browseState.data?.entries ?? [], browseFilterQuery),
925 [browseFilterQuery, browseState.data?.entries],
926 );
927​
928 return (
929 <>
930 <SectionTitle>Browse folders</SectionTitle>
931 {!canReadFiles && !fileAccess.isPending ? (
932 <ErrorBanner message={fileAccess.error ?? "This connection cannot browse host folders."} />
933 ) : null}
934 {browseState.error ? <ErrorBanner message={browseState.error} /> : null}
935 <ListSection>
936 {fileAccess.isPending || (browseState.isPending && browseState.data === null) ? (
937 <View className="items-center py-5">
938 <AppActivityIndicator colorClassName="accent-icon-muted" />
939 </View>
940 ) : null}
941 {browsePath.canBrowseUp ? (
942 <ListRow
943 title=".."
944 icon={
945 <SymbolView
946 name="arrow.turn.left.up"
947 size={Platform.OS === "android" ? 24 : 17}
948 tintColorClassName="accent-icon-muted"
949 type="monochrome"
950 />
951 }
952 isFirst
953 right={null}
954 onPress={() => {
955 if (browsePath.parentPath) {
956 void props.navigateToBrowsePath({
957 browseDirectoryPath: browsePath.parentPath,
958 });
959 }
960 }}
961 />
962 ) : null}
963 {visibleBrowseEntries.map((entry, index) => (
964 <ListRow
965 key={entry.fullPath}
966 title={entry.name}
967 icon={
968 <SymbolView
969 name="folder"
970 size={Platform.OS === "android" ? 24 : 17}
971 tintColorClassName="accent-icon-muted"
972 type="monochrome"
973 />
974 }
975 isFirst={index === 0 && !browsePath.canBrowseUp}
976 right={null}
977 onPress={() => {
978 void props.navigateToBrowsePath({
979 browseDirectoryPath: browsePath.directoryPath,
980 selectedDirectoryName: entry.name,
981 });
982 }}
983 />
984 ))}
985 </ListSection>
986 </>
987 );
989​
990export function AddProjectNewScreen(props: { readonly environmentId?: string | string[] }) {
991 const navigation = useNavigation();
992 const environmentOptions = useEnvironmentOptions().filter(
993 (option) => option.newProjectsRoot !== null,
994 );
995 const [selectedEnvironmentId, setSelectedEnvironmentId] = useState(
996 () => stringParam(props.environmentId) as EnvironmentId | null,
997 );
998 const environment = resolveAddProjectEnvironment(environmentOptions, selectedEnvironmentId);
999 const createNew = useAtomCommand(projectEnvironment.createNew, { reportFailure: false });
1000 const publishRepository = useAtomCommand(sourceControlEnvironment.publishRepository, {
1001 reportFailure: false,
1002 });
1003 const discoveryState = useEnvironmentQuery(
1004 environment === null
1005 ? null
1006 : sourceControlEnvironment.discovery({
1007 environmentId: environment.environmentId,
1008 input: {},
1009 }),
1010 );
1011 const publishTargets = getNewProjectPublishTargets(discoveryState.data);
1012 const [name, setName] = useState("");
1013 const [publishes, setPublishes] = useState(false);
1014 const [publishKind, setPublishKind] = useState<SourceControlProviderKind | null>(null);
1015 const publishTarget = getNewProjectPublishTarget(publishTargets, publishKind);
1016 const [isSubmitting, setIsSubmitting] = useState(false);
1017 const [error, setError] = useState<string | null>(null);
1018 const trimmedName = name.trim();
1019 const pathPreview =
1020 environment?.newProjectsRoot != null
1021 ? getNewProjectPathPreview(environment.newProjectsRoot, trimmedName)
1022 : null;
1023​
1024 const showMachines =
1025 environmentOptions.length > 1 || (environment === null && environmentOptions.length > 0);
1026 const machineRows = showMachines ? (
1027 <ListSection>
1028 {environmentOptions.map((option, index) => {
1029 const selected = option.environmentId === environment?.environmentId;
1030 return (
1031 <ListRow
1032 key={option.environmentId}
1033 title={option.label}
1034 icon={
1035 <EnvironmentMachineSymbol
1036 kind={option.machine}
1037 size={Platform.OS === "android" ? 24 : 17}
1038 tintColorClassName="accent-icon"
1039 />
1041 selected={selected}
1042 disabled={isSubmitting}
1043 isFirst={index === 0}
1044 right={
1045 selected ? (
1046 <SymbolView
1047 name="checkmark"
1048 size={Platform.OS === "android" ? 20 : 14}
1049 tintColorClassName="accent-icon"
1050 type="monochrome"
1051 />
1052 ) : null
1054 onPress={() => setSelectedEnvironmentId(option.environmentId)}
1055 />
1056 );
1057 })}
1058 </ListSection>
1059 ) : null;
1060​
1061 // State lags a render behind, so a double tap could start a second create.
1062 const submittingRef = useRef(false);
1063 const submit = async () => {
1064 if (!environment || trimmedName.length === 0 || submittingRef.current) return;
1065 submittingRef.current = true;
1066 setError(null);
1067 setIsSubmitting(true);
1068 try {
1069 const result = await createNew({
1070 environmentId: environment.environmentId,
1071 input: { name: trimmedName },
1072 });
1073 if (AsyncResult.isFailure(result)) {
1074 setError(errorMessage(Cause.squash(result.cause)));
1075 return;
1077 const { projectId, workspaceRoot, commitError } = result.value;
1078 if (commitError !== undefined) {
1079 Dialog.alert("Created without a first commit", commitError);
1081 if (publishes && publishTarget !== null) {
1082 void publishRepository({
1083 environmentId: environment.environmentId,
1084 input: {
1085 cwd: workspaceRoot,
1086 provider: publishTarget.definition.kind,
1087 repository: getNewProjectRepository(publishTarget, workspaceRoot),
1088 visibility: "private",
1089 },
1090 }).then((publishResult) => {
1091 if (AsyncResult.isFailure(publishResult)) {
1092 Dialog.alert(
1093 `Could not create the ${publishTarget.definition.label} repository`,
1094 errorMessage(Cause.squash(publishResult.cause)),
1095 );
1097 });
1099 // The draft screen resolves its project from the client store, so it
1100 // must not open before the create event has arrived.
1101 const project = await waitForProject(
1102 { environmentId: environment.environmentId, projectId },
1103 15_000,
1104 );
1105 if (project === null) {
1106 setName("");
1107 setError(
1108 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1109 );
1110 return;
1112 openNewTaskDraft(navigation, {
1113 environmentId: environment.environmentId,
1114 projectId,
1115 title: trimmedName,
1116 });
1117 } finally {
1118 submittingRef.current = false;
1119 setIsSubmitting(false);
1121 };
1122​
1123 return (
1124 <AddProjectShell title="New project">
1125 {error ? <ErrorBanner message={error} /> : null}
1126 {environment ? (
1127 <>
1128 <TextInput
1129 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
1130 value={name}
1131 onChangeText={setName}
1132 autoCorrect={false}
1133 autoFocus
1134 placeholder="Project name"
1135 returnKeyType="done"
1136 onSubmitEditing={() => void submit()}
1137 />
1138 {pathPreview !== null ? (
1139 <Text className="px-1 text-sm leading-snug text-foreground-muted" numberOfLines={2}>
1140 {trimmedName.length > 0
1141 ? `Creates ${pathPreview}`
1142 : `Goes in ${environment.newProjectsRoot}`}
1143 {showMachines ? ` on ${environment.label}` : null}
1144 </Text>
1145 ) : null}
1146 {machineRows}
1147 {publishTarget !== null ? (
1148 <ListSection>
1149 <ListRow
1150 title={`Create private repository on ${publishTarget.definition.label}`}
1151 subtitle={
1152 trimmedName.length > 0 && pathPreview !== null
1153 ? getNewProjectRepository(publishTarget, pathPreview)
1154 : publishTarget.owner
1156 icon={
1157 <SourceControlIcon
1158 kind={publishTarget.definition.icon}
1159 size={Platform.OS === "android" ? 24 : 18}
1160 colorClassName="accent-icon"
1161 />
1163 isFirst
1164 right={
1165 <ThemedSwitch
1166 accessibilityLabel={`Create private repository on ${publishTarget.definition.label}`}
1167 value={publishes}
1168 onValueChange={setPublishes}
1169 />
1171 onPress={() => setPublishes((current) => !current)}
1172 />
1173 {publishes && publishTargets.length > 1
1174 ? publishTargets.map((target) => {
1175 const selected = target.definition.kind === publishTarget.definition.kind;
1176 return (
1177 <ListRow
1178 key={target.definition.kind}
1179 title={target.definition.label}
1180 icon={
1181 <SourceControlIcon
1182 kind={target.definition.icon}
1183 size={Platform.OS === "android" ? 24 : 17}
1184 colorClassName="accent-icon"
1185 />
1187 selected={selected}
1188 disabled={isSubmitting}
1189 right={
1190 selected ? (
1191 <SymbolView
1192 name="checkmark"
1193 size={Platform.OS === "android" ? 20 : 14}
1194 tintColorClassName="accent-icon"
1195 type="monochrome"
1196 />
1197 ) : null
1199 onPress={() => setPublishKind(target.definition.kind)}
1200 />
1201 );
1202 })
1203 : null}
1204 </ListSection>
1205 ) : null}
1206 <PrimaryActionButton
1207 label="Create project"
1208 disabled={isSubmitting || trimmedName.length === 0}
1209 onPress={() => void submit()}
1210 loading={isSubmitting}
1211 />
1212 <ListSection>
1213 <ListRow
1214 title="Add existing project"
1215 subtitle="Open a folder or clone a repository"
1216 icon={
1217 <SymbolView
1218 name="folder.badge.plus"
1219 size={Platform.OS === "android" ? 24 : 17}
1220 tintColorClassName="accent-icon"
1221 type="monochrome"
1222 />
1224 isFirst
1225 onPress={() =>
1226 navigation.canGoBack()
1227 ? navigation.goBack()
1228 : navigation.dispatch(StackActions.replace("AddProject"))
1230 />
1231 </ListSection>
1232 </>
1233 ) : environmentOptions.length > 0 ? (
1234 machineRows
1235 ) : (
1236 <EmptyEnvironmentState />
1237 )}
1238 </AddProjectShell>
1239 );
1241​
1242export function AddProjectLocalFolderScreen(props: { readonly environmentId?: string | string[] }) {
1243 const environment = useEnvironmentFromParam(props.environmentId);
1244 const canCreateProject = useEnvironmentScope(
1245 environment?.environmentId ?? null,
1246 AuthOrchestrationOperateScope,
1247 );
1248 const createProject = useCreateProject(environment);
1249 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
1250 useBrowsePathInput(environment);
1251 const [isSubmitting, setIsSubmitting] = useState(false);
1252 const [error, setError] = useState<string | null>(null);
1253​
1254 const submitPath = useCallback(async () => {
1255 if (!environment || isBrowseNavigating || isSubmitting) return;
1256 setError(null);
1257 const resolved = resolveAddProjectPath({
1258 rawPath: pathInput,
1259 currentProjectCwd: null,
1260 platform: environment.platform,
1261 });
1262 if (!resolved.ok) {
1263 setError(resolved.error);
1264 return;
1266​
1267 setIsSubmitting(true);
1268 const result = await createProject(resolved.path);
1269 if (result && AsyncResult.isFailure(result)) {
1270 setError(errorMessage(Cause.squash(result.cause)));
1272 setIsSubmitting(false);
1273 }, [createProject, environment, isBrowseNavigating, isSubmitting, pathInput]);
1274​
1275 return (
1276 <AddProjectShell title="Local folder">
1277 {error ? <ErrorBanner message={error} /> : null}
1278 {environment ? (
1279 <>
1280 {!canCreateProject ? (
1281 <ErrorBanner message="This connection cannot add projects." />
1282 ) : null}
1283 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1284 <PrimaryActionButton
1285 label="Add project"
1286 disabled={!canCreateProject || isBrowseNavigating || isSubmitting}
1287 onPress={submitPath}
1288 loading={isSubmitting}
1289 />
1290 <FolderBrowser
1291 environment={environment}
1292 navigateToBrowsePath={navigateToBrowsePath}
1293 pathInput={pathInput}
1294 setPathInput={setPathInput}
1295 />
1296 </>
1297 ) : (
1298 <EmptyEnvironmentState />
1299 )}
1300 </AddProjectShell>
1301 );
1303​
1304export function AddProjectDestinationScreen(props: {
1305 readonly environmentId?: string | string[];
1306 readonly remoteUrl?: string | string[];
1307 readonly repositoryTitle?: string | string[];
1308 readonly repositoryName?: string | string[];
1309 readonly prompt?: string | string[];
1310}) {
1311 const cloneRepository = useAtomCommand(sourceControlEnvironment.cloneRepository, {
1312 reportFailure: false,
1313 });
1314 const startProjectClone = useAtomCommand(sourceControlEnvironment.startProjectClone, {
1315 reportFailure: false,
1316 });
1317 const navigation = useNavigation();
1318 const environment = useEnvironmentFromParam(props.environmentId);
1319 const canWriteSourceControl = useEnvironmentScope(
1320 environment?.environmentId ?? null,
1321 AuthSourceControlWriteScope,
1322 );
1323 const canCreateProject = useEnvironmentScope(
1324 environment?.environmentId ?? null,
1325 AuthOrchestrationOperateScope,
1326 );
1327 const canCloneProject = canWriteSourceControl && canCreateProject;
1328 const createProject = useCreateProject(environment);
1329 const remoteUrl = stringParam(props.remoteUrl);
1330 const repositoryTitle = stringParam(props.repositoryTitle);
1331 const prompt = stringParam(props.prompt);
1332 const repositoryName = stringParam(props.repositoryName)?.trim() ?? "";
1333 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } = useBrowsePathInput(
1334 environment,
1335 repositoryName,
1336 );
1337 const [isSubmitting, setIsSubmitting] = useState(false);
1338 const [error, setError] = useState<string | null>(null);
1339​
1340 const submitPath = useCallback(async () => {
1341 if (
1342 !environment ||
1343 !readEnvironmentScope(environment.environmentId, AuthSourceControlWriteScope) ||
1344 !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope) ||
1345 !remoteUrl ||
1346 isBrowseNavigating ||
1347 isSubmitting
1348 ) {
1349 return;
1351 setError(null);
1352 const resolved = resolveAddProjectPath({
1353 rawPath: pathInput,
1354 currentProjectCwd: null,
1355 platform: environment.platform,
1356 });
1357 if (!resolved.ok) {
1358 setError(resolved.error);
1359 return;
1361​
1362 setIsSubmitting(true);
1363 if (environment.supportsCloneTracking) {
1364 const projectId = ProjectId.make(uuidv4());
1365 const title = inferProjectTitleFromPath(resolved.path);
1366 const startResult = await startProjectClone({
1367 environmentId: environment.environmentId,
1368 input: {
1369 projectId,
1370 title,
1371 createdAt: new Date().toISOString(),
1372 remoteUrl,
1373 destinationPath: resolved.path,
1374 },
1375 });
1376 if (AsyncResult.isFailure(startResult)) {
1377 setError(errorMessage(Cause.squash(startResult.cause)));
1378 } else {
1379 // The draft screen resolves its project from the client store, so it
1380 // must not open before the create event has arrived (it would fall back
1381 // to the project picker and lose the clone controls).
1382 const project = await waitForProject(
1383 { environmentId: environment.environmentId, projectId },
1384 15_000,
1385 );
1386 if (project === null) {
1387 setError(
1388 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1389 );
1390 } else {
1391 openNewTaskDraft(navigation, {
1392 environmentId: environment.environmentId,
1393 projectId,
1394 title,
1395 cloning: "1",
1396 ...(prompt
1397 ? await draftWithPrompt(environment.environmentId, projectId, prompt).then(
1398 (draftId) => ({ draftId }),
1399 () => ({}),
1401 : {}),
1402 });
1405 setIsSubmitting(false);
1406 return;
1408 const cloneResult = await cloneRepository({
1409 environmentId: environment.environmentId,
1410 input: {
1411 remoteUrl,
1412 destinationPath: resolved.path,
1413 },
1414 });
1415 if (AsyncResult.isFailure(cloneResult)) {
1416 setError(errorMessage(Cause.squash(cloneResult.cause)));
1417 } else {
1418 const createResult = await createProject(cloneResult.value.cwd);
1419 if (createResult && AsyncResult.isFailure(createResult)) {
1420 setError(errorMessage(Cause.squash(createResult.cause)));
1423 setIsSubmitting(false);
1424 }, [
1425 cloneRepository,
1426 createProject,
1427 environment,
1428 isBrowseNavigating,
1429 isSubmitting,
1430 navigation,
1431 pathInput,
1432 prompt,
1433 remoteUrl,
1434 startProjectClone,
1435 ]);
1436​
1437 return (
1438 <AddProjectShell title="Clone destination">
1439 {error ? <ErrorBanner message={error} /> : null}
1440 {repositoryTitle ? (
1441 <View className="rounded-[24px] bg-grouped-card px-4 py-3">
1442 <Text className="text-base font-t3-bold">{repositoryTitle}</Text>
1443 <Text className="mt-0.5 text-xs text-foreground-muted" numberOfLines={2}>
1444 {remoteUrl}
1445 </Text>
1446 </View>
1447 ) : null}
1448 {environment ? (
1449 <>
1450 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1451 <PrimaryActionButton
1452 label="Clone project"
1453 disabled={!canCloneProject || isBrowseNavigating || isSubmitting || !remoteUrl}
1454 onPress={submitPath}
1455 loading={isSubmitting}
1456 />
1457 {!canCloneProject ? (
1458 <Text className="text-sm text-foreground-muted">
1459 This connection cannot clone projects.
1460 </Text>
1461 ) : null}
1462 <FolderBrowser
1463 environment={environment}
1464 navigateToBrowsePath={navigateToBrowsePath}
1465 pathInput={pathInput}
1466 setPathInput={setPathInput}
1467 pinnedDirectoryName={repositoryName}
1468 />
1469 </>
1470 ) : (
1471 <EmptyEnvironmentState />
1472 )}
1473 </AddProjectShell>
1474 );