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

AddProjectScreen.tsx

1,468 lines51.2 KB

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