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

AddProjectScreen.tsx

1,466 lines50.2 KB

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