Open History to see the last commit
1import {
2 addProjectRemoteSourceLabel,
3 addProjectRemoteSourcePathHint,
4 addProjectRemoteSourceProvider,
5 appendBrowsePathSegment,
6 buildAddProjectRemoteSourceReadiness,
7 buildProjectCreateCommand,
8 canNavigateUp,
9 ensureBrowseDirectoryPath,
10 findExistingAddProject,
11 getAddProjectInitialQuery,
12 getBrowseDirectoryPath,
13 getBrowseLeafPathSegment,
14 getBrowseParentPath,
15 hasTrailingPathSeparator,
16 inferProjectTitleFromPath,
17 isFilesystemBrowseQuery,
18 resolveAddProjectPath,
19 sortAddProjectProviderSources,
20 type AddProjectRemoteSource,
21} from "@t3tools/client-runtime";
22import { CommandId, type EnvironmentId, ProjectId } from "@t3tools/contracts";
23import { useLocalSearchParams, useRouter } from "expo-router";
24import { SymbolView } from "expo-symbols";
25import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
26import { ActivityIndicator, Alert, Pressable, ScrollView, View } from "react-native";
27import { useSafeAreaInsets } from "react-native-safe-area-context";
28import * as Arr from "effect/Array";
29import * as Order from "effect/Order";
30
31import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
32import { ErrorBanner } from "../../components/ErrorBanner";
33import { SourceControlIcon } from "../../components/SourceControlIcon";
34import { useThemeColor } from "../../lib/useThemeColor";
35import { uuidv4 } from "../../lib/uuid";
36import { getEnvironmentClient } from "../../state/environment-session-registry";
37import { useFilesystemBrowse } from "../../state/use-filesystem-browse";
38import { useRemoteCatalog } from "../../state/use-remote-catalog";
39import { useRemoteEnvironmentState } from "../../state/use-remote-environment-registry";
40import {
41 refreshSourceControlDiscoveryForEnvironment,
42 useSourceControlDiscovery,
43} from "../../state/use-source-control-discovery";
44
45interface EnvironmentOption {
46 readonly environmentId: EnvironmentId;
47 readonly label: string;
48 readonly platform: string;
49 readonly baseDirectory: string | null;
50}
51
52const environmentOptionOrder = Order.mapInput(
53 Order.Struct({
54 label: Order.String,
55 }),
56 (environment: EnvironmentOption) => ({ label: environment.label }),
57);
58
59const browseEntryOrder = Order.mapInput(
60 Order.String,
61 (entry: { readonly name: string }) => entry.name,
62);
63
64function platformFromOs(os: string | null | undefined): string {
65 if (os === "windows") return "Win32";
66 if (os === "darwin") return "MacIntel";
67 if (os === "linux") return "Linux";
68 return "";
69}
70
71function errorMessage(error: unknown): string {
72 return error instanceof Error && error.message.trim().length > 0
73 ? error.message
74 : "An error occurred.";
75}
76
77function stringParam(value: string | string[] | undefined): string | null {
78 if (Array.isArray(value)) return value[0] ?? null;
79 return value ?? null;
80}
81
82function sourceFromParam(value: string | string[] | undefined): AddProjectRemoteSource {
83 const source = stringParam(value);
84 if (
85 source === "url" ||
86 source === "github" ||
87 source === "gitlab" ||
88 source === "bitbucket" ||
89 source === "azure-devops"
90 ) {
91 return source;
92 }
93 return "url";
94}
95
96function SectionTitle(props: { readonly children: string }) {
97 return (
98 <Text
99 className="px-1 text-[11px] font-t3-bold uppercase text-foreground-muted"
100 style={{ letterSpacing: 0.7 }}
101 >
102 {props.children}
103 </Text>
104 );
105}
106
107function AddProjectShell(props: { readonly children: ReactNode }) {
108 const insets = useSafeAreaInsets();
109
110 return (
111 <View className="flex-1 bg-sheet">
112 <ScrollView
113 keyboardShouldPersistTaps="handled"
114 contentInsetAdjustmentBehavior="automatic"
115 contentContainerStyle={{
116 paddingHorizontal: 20,
117 paddingTop: 16,
118 paddingBottom: Math.max(insets.bottom, 18) + 18,
119 gap: 10,
120 }}
121 >
122 {props.children}
123 </ScrollView>
124 </View>
125 );
126}
127
128function ListSection(props: { readonly children: ReactNode }) {
129 return <View className="overflow-hidden rounded-[24px] bg-card">{props.children}</View>;
130}
131
132function ListRow(props: {
133 readonly title: string;
134 readonly subtitle?: string | null;
135 readonly icon: ReactNode;
136 readonly disabled?: boolean;
137 readonly selected?: boolean;
138 readonly isFirst?: boolean;
139 readonly right?: ReactNode;
140 readonly onPress?: () => void;
141}) {
142 const borderColor = useThemeColor("--color-border-subtle");
143 const chevronColor = useThemeColor("--color-chevron");
144
145 return (
146 <Pressable
147 disabled={props.disabled}
148 onPress={props.onPress}
149 className="bg-card px-3.5 py-2.5 active:opacity-70"
150 style={{
151 opacity: props.disabled ? 0.45 : 1,
152 borderTopWidth: props.isFirst ? 0 : 1,
153 borderTopColor: borderColor,
154 }}
155 >
156 <View className="flex-row items-center gap-3">
157 <View
158 className={
159 props.selected
160 ? "h-7 w-7 items-center justify-center rounded-full bg-primary"
161 : "h-7 w-7 items-center justify-center"
162 }
163 >
164 {props.icon}
165 </View>
166 <View className="flex-1 gap-0.5">
167 <Text className="text-[16px] leading-[21px] font-t3-bold">{props.title}</Text>
168 {props.subtitle ? (
169 <Text className="text-[13px] leading-[17px] text-foreground-muted" numberOfLines={2}>
170 {props.subtitle}
171 </Text>
172 ) : null}
173 </View>
174 {"right" in props ? (
175 props.right
176 ) : !props.disabled ? (
177 <SymbolView name="chevron.right" size={13} tintColor={chevronColor} type="monochrome" />
178 ) : null}
179 </View>
180 </Pressable>
181 );
182}
183
184function PrimaryActionButton(props: {
185 readonly label: string;
186 readonly disabled?: boolean;
187 readonly loading?: boolean;
188 readonly onPress: () => void;
189}) {
190 const primaryForeground = useThemeColor("--color-primary-foreground");
191
192 return (
193 <Pressable
194 disabled={props.disabled}
195 onPress={props.onPress}
196 className="h-12 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"
197 >
198 {props.loading ? (
199 <ActivityIndicator color={String(primaryForeground)} />
200 ) : (
201 <Text className="text-[14px] font-t3-bold text-primary-foreground">{props.label}</Text>
202 )}
203 </Pressable>
204 );
205}
206
207function ProjectPathInput(props: {
208 readonly value: string;
209 readonly onChangeText: (value: string) => void;
210 readonly onSubmit: () => void;
211}) {
212 return (
213 <TextInput
214 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-[15px] leading-[20px]"
215 value={props.value}
216 onChangeText={props.onChangeText}
217 autoCapitalize="none"
218 autoCorrect={false}
219 placeholder="~/projects/my-app"
220 returnKeyType="done"
221 onSubmitEditing={props.onSubmit}
222 />
223 );
224}
225
226function useEnvironmentOptions(): ReadonlyArray<EnvironmentOption> {
227 const { serverConfigByEnvironmentId } = useRemoteCatalog();
228 const { savedConnectionsById } = useRemoteEnvironmentState();
229
230 return useMemo<ReadonlyArray<EnvironmentOption>>(() => {
231 const options = Object.values(savedConnectionsById).map((connection) => {
232 const config = serverConfigByEnvironmentId[connection.environmentId];
233 return {
234 environmentId: connection.environmentId,
235 label: connection.environmentLabel,
236 platform: platformFromOs(config?.environment.platform.os ?? null),
237 baseDirectory: config?.settings.addProjectBaseDirectory ?? null,
238 };
239 });
240 return Arr.sort(options, environmentOptionOrder);
241 }, [savedConnectionsById, serverConfigByEnvironmentId]);
242}
243
244function useSelectedEnvironment(): {
245 readonly environmentOptions: ReadonlyArray<EnvironmentOption>;
246 readonly selectedEnvironment: EnvironmentOption | null;
247 readonly setSelectedEnvironmentId: (environmentId: EnvironmentId) => void;
248} {
249 const router = useRouter();
250 const params = useLocalSearchParams<{ environmentId?: string }>();
251 const environmentOptions = useEnvironmentOptions();
252 const requestedEnvironmentId = stringParam(params.environmentId) as EnvironmentId | null;
253 const selectedEnvironment =
254 environmentOptions.find(
255 (environment) => environment.environmentId === requestedEnvironmentId,
256 ) ??
257 environmentOptions[0] ??
258 null;
259
260 return {
261 environmentOptions,
262 selectedEnvironment,
263 setSelectedEnvironmentId: (environmentId) => router.setParams({ environmentId }),
264 };
265}
266
267function EmptyEnvironmentState() {
268 const router = useRouter();
269
270 return (
271 <View className="items-center gap-3 rounded-2xl bg-card px-5 py-8">
272 <Text className="text-center text-[17px] font-t3-bold">No environments connected</Text>
273 <Text className="text-center text-[14px] leading-[20px] text-foreground-muted">
274 Add an environment before adding a project.
275 </Text>
276 <Pressable
277 onPress={() => router.replace("/connections/new")}
278 className="mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
279 >
280 <Text className="text-[13px] font-t3-bold text-primary-foreground">Add environment</Text>
281 </Pressable>
282 </View>
283 );
284}
285
286function SourceControlRow(props: {
287 readonly source: AddProjectRemoteSource;
288 readonly selectedEnvironmentId: EnvironmentId;
289 readonly ready: boolean;
290 readonly hint: string;
291 readonly isFirst: boolean;
292}) {
293 const router = useRouter();
294 const iconColor = useThemeColor("--color-icon");
295 const title =
296 props.source === "url" ? "Git URL" : `${addProjectRemoteSourceLabel(props.source)} repository`;
297 const subtitle =
298 props.source === "url"
299 ? "Clone from a remote URL"
300 : `Clone ${addProjectRemoteSourceLabel(props.source)} ${props.hint}`;
301 const icon =
302 props.source === "url" ? (
303 <SymbolView name="link" size={17} tintColor={iconColor} type="monochrome" />
304 ) : (
305 <SourceControlIcon kind={props.source} size={18} color={String(iconColor)} />
306 );
307
308 if (!props.ready) {
309 return (
310 <ListRow title={title} subtitle={props.hint} icon={icon} disabled isFirst={props.isFirst} />
311 );
312 }
313
314 return (
315 <ListRow
316 title={title}
317 subtitle={subtitle}
318 icon={icon}
319 isFirst={props.isFirst}
320 onPress={() =>
321 router.push({
322 pathname: "/new/add-project/repository",
323 params: {
324 environmentId: props.selectedEnvironmentId,
325 source: props.source,
326 },
327 })
328 }
329 />
330 );
331}
332
333export function AddProjectSourceScreen() {
334 const router = useRouter();
335 const accentColor = useThemeColor("--color-icon-muted");
336 const iconColor = useThemeColor("--color-icon");
337 const { environmentOptions, selectedEnvironment, setSelectedEnvironmentId } =
338 useSelectedEnvironment();
339 const discoveryState = useSourceControlDiscovery(selectedEnvironment?.environmentId ?? null);
340 const readiness = useMemo(
341 () => buildAddProjectRemoteSourceReadiness(discoveryState.data),
342 [discoveryState.data],
343 );
344
345 useEffect(() => {
346 if (!selectedEnvironment) return;
347 void refreshSourceControlDiscoveryForEnvironment(selectedEnvironment.environmentId);
348 }, [selectedEnvironment]);
349
350 return (
351 <AddProjectShell>
352 {environmentOptions.length === 0 ? <EmptyEnvironmentState /> : null}
353
354 {environmentOptions.length > 1 ? (
355 <>
356 <SectionTitle>Connected environments</SectionTitle>
357 <ListSection>
358 {environmentOptions.map((environment, index) => (
359 <ListRow
360 key={environment.environmentId}
361 title={environment.label}
362 subtitle={environment.environmentId}
363 icon={
364 <SymbolView
365 name="server.rack"
366 size={17}
367 tintColor={iconColor}
368 type="monochrome"
369 />
370 }
371 selected={environment.environmentId === selectedEnvironment?.environmentId}
372 isFirst={index === 0}
373 right={
374 environment.environmentId === selectedEnvironment?.environmentId ? (
375 <SymbolView
376 name="checkmark"
377 size={14}
378 tintColor={iconColor}
379 type="monochrome"
380 />
381 ) : null
382 }
383 onPress={() => setSelectedEnvironmentId(environment.environmentId)}
384 />
385 ))}
386 </ListSection>
387 </>
388 ) : null}
389
390 {selectedEnvironment ? (
391 <>
392 <ListSection>
393 <ListRow
394 title="Local folder"
395 subtitle="Browse a folder on disk"
396 icon={
397 <SymbolView
398 name="folder.badge.plus"
399 size={17}
400 tintColor={iconColor}
401 type="monochrome"
402 />
403 }
404 isFirst
405 onPress={() =>
406 router.push({
407 pathname: "/new/add-project/local",
408 params: { environmentId: selectedEnvironment.environmentId },
409 })
410 }
411 />
412 {(["url", ...sortAddProjectProviderSources(readiness)] as AddProjectRemoteSource[]).map(
413 (candidate) => (
414 <SourceControlRow
415 key={candidate}
416 source={candidate}
417 selectedEnvironmentId={selectedEnvironment.environmentId}
418 ready={readiness[candidate].ready}
419 hint={
420 readiness[candidate].ready
421 ? addProjectRemoteSourcePathHint(candidate)
422 : (readiness[candidate].hint ?? "")
423 }
424 isFirst={false}
425 />
426 ),
427 )}
428 </ListSection>
429 {discoveryState.isPending ? <ActivityIndicator color={accentColor} /> : null}
430 </>
431 ) : null}
432 </AddProjectShell>
433 );
434}
435
436function useCreateProject(environment: EnvironmentOption | null) {
437 const router = useRouter();
438 const { projects } = useRemoteCatalog();
439
440 return useCallback(
441 async (workspaceRoot: string) => {
442 if (!environment) return;
443 const client = getEnvironmentClient(environment.environmentId);
444 if (!client) throw new Error("Environment API is not available.");
445
446 const existing = findExistingAddProject({
447 projects,
448 environmentId: environment.environmentId,
449 path: workspaceRoot,
450 });
451 if (existing) {
452 Alert.alert("Project already exists", existing.title);
453 router.replace({
454 pathname: "/new/draft",
455 params: {
456 environmentId: existing.environmentId,
457 projectId: existing.id,
458 title: existing.title,
459 },
460 });
461 return;
462 }
463
464 const projectId = ProjectId.make(uuidv4());
465 await client.orchestration.dispatchCommand(
466 buildProjectCreateCommand({
467 commandId: CommandId.make(uuidv4()),
468 projectId,
469 workspaceRoot,
470 createdAt: new Date().toISOString(),
471 }),
472 );
473 router.replace({
474 pathname: "/new/draft",
475 params: {
476 environmentId: environment.environmentId,
477 projectId,
478 title: inferProjectTitleFromPath(workspaceRoot),
479 },
480 });
481 },
482 [environment, projects, router],
483 );
484}
485
486function useEnvironmentFromParam(): EnvironmentOption | null {
487 const params = useLocalSearchParams<{ environmentId?: string }>();
488 const environmentOptions = useEnvironmentOptions();
489 const environmentId = stringParam(params.environmentId) as EnvironmentId | null;
490 return (
491 environmentOptions.find((environment) => environment.environmentId === environmentId) ??
492 environmentOptions[0] ??
493 null
494 );
495}
496
497export function AddProjectRepositoryScreen() {
498 const router = useRouter();
499 const params = useLocalSearchParams<{ environmentId?: string; source?: string }>();
500 const environment = useEnvironmentFromParam();
501 const source = sourceFromParam(params.source);
502 const [repositoryInput, setRepositoryInput] = useState("");
503 const [isSubmitting, setIsSubmitting] = useState(false);
504 const [error, setError] = useState<string | null>(null);
505
506 const lookupRepository = useCallback(async () => {
507 if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return;
508 setError(null);
509 setIsSubmitting(true);
510 try {
511 const provider = addProjectRemoteSourceProvider(source);
512 if (!provider) {
513 const remoteUrl = repositoryInput.trim();
514 router.push({
515 pathname: "/new/add-project/destination",
516 params: {
517 environmentId: environment.environmentId,
518 source,
519 remoteUrl,
520 repositoryTitle: remoteUrl,
521 },
522 });
523 return;
524 }
525
526 const client = getEnvironmentClient(environment.environmentId);
527 if (!client) throw new Error("Environment API is not available.");
528 const repository = await client.sourceControl.lookupRepository({
529 provider,
530 repository: repositoryInput.trim(),
531 });
532 router.push({
533 pathname: "/new/add-project/destination",
534 params: {
535 environmentId: environment.environmentId,
536 source,
537 remoteUrl: repository.sshUrl,
538 repositoryTitle: repository.nameWithOwner,
539 },
540 });
541 } catch (nextError) {
542 setError(errorMessage(nextError));
543 } finally {
544 setIsSubmitting(false);
545 }
546 }, [environment, isSubmitting, repositoryInput, router, source]);
547
548 return (
549 <AddProjectShell>
550 {error ? <ErrorBanner message={error} /> : null}
551 <TextInput
552 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-[15px] leading-[20px]"
553 value={repositoryInput}
554 onChangeText={setRepositoryInput}
555 autoCapitalize="none"
556 autoCorrect={false}
557 placeholder={
558 source === "url"
559 ? "https://github.com/org/repo.git"
560 : addProjectRemoteSourcePathHint(source)
561 }
562 returnKeyType="next"
563 onSubmitEditing={() => void lookupRepository()}
564 />
565 <PrimaryActionButton
566 label={source === "url" ? "Continue" : "Lookup repository"}
567 disabled={isSubmitting || repositoryInput.trim().length === 0}
568 onPress={() => void lookupRepository()}
569 loading={isSubmitting}
570 />
571 </AddProjectShell>
572 );
573}
574
575function FolderBrowser(props: {
576 readonly environment: EnvironmentOption;
577 readonly pathInput: string;
578 readonly setPathInput: (path: string) => void;
579}) {
580 const accentColor = useThemeColor("--color-icon-muted");
581 const browseDirectoryPath = useMemo(
582 () =>
583 isFilesystemBrowseQuery(props.pathInput, props.environment.platform)
584 ? getBrowseDirectoryPath(props.pathInput)
585 : "",
586 [props.environment.platform, props.pathInput],
587 );
588 const browseFilterQuery =
589 browseDirectoryPath.length > 0 && !hasTrailingPathSeparator(props.pathInput)
590 ? getBrowseLeafPathSegment(props.pathInput).toLowerCase()
591 : "";
592 const browseInput = useMemo(
593 () => (browseDirectoryPath.length > 0 ? { partialPath: browseDirectoryPath } : null),
594 [browseDirectoryPath],
595 );
596 const browseState = useFilesystemBrowse(props.environment.environmentId, browseInput);
597 const visibleBrowseEntries = useMemo(
598 () =>
599 Arr.sort(
600 Arr.filter(
601 browseState.data?.entries ?? [],
602 (entry) =>
603 !entry.name.startsWith(".") && entry.name.toLowerCase().startsWith(browseFilterQuery),
604 ),
605 browseEntryOrder,
606 ),
607 [browseFilterQuery, browseState.data?.entries],
608 );
609 const parentBrowsePath = getBrowseParentPath(browseDirectoryPath);
610 const canBrowseUpPath = canNavigateUp(browseDirectoryPath);
611
612 return (
613 <>
614 <SectionTitle>Browse folders</SectionTitle>
615 {browseState.error ? <ErrorBanner message={browseState.error} /> : null}
616 <ListSection>
617 {browseState.isPending && browseState.data === null ? (
618 <View className="items-center py-5">
619 <ActivityIndicator color={accentColor} />
620 </View>
621 ) : null}
622 {canBrowseUpPath ? (
623 <ListRow
624 title=".."
625 icon={
626 <SymbolView
627 name="arrow.turn.left.up"
628 size={17}
629 tintColor={accentColor}
630 type="monochrome"
631 />
632 }
633 isFirst
634 right={null}
635 onPress={() => {
636 if (parentBrowsePath) props.setPathInput(parentBrowsePath);
637 }}
638 />
639 ) : null}
640 {visibleBrowseEntries.map((entry, index) => (
641 <ListRow
642 key={entry.fullPath}
643 title={entry.name}
644 icon={<SymbolView name="folder" size={17} tintColor={accentColor} type="monochrome" />}
645 isFirst={index === 0 && !canBrowseUpPath}
646 right={null}
647 onPress={() =>
648 props.setPathInput(
649 browseDirectoryPath.length > 0
650 ? appendBrowsePathSegment(browseDirectoryPath, entry.name)
651 : ensureBrowseDirectoryPath(entry.fullPath),
652 )
653 }
654 />
655 ))}
656 </ListSection>
657 </>
658 );
659}
660
661export function AddProjectLocalFolderScreen() {
662 const environment = useEnvironmentFromParam();
663 const createProject = useCreateProject(environment);
664 const [pathInput, setPathInput] = useState(() =>
665 getAddProjectInitialQuery(environment?.baseDirectory),
666 );
667 const [isSubmitting, setIsSubmitting] = useState(false);
668 const [error, setError] = useState<string | null>(null);
669
670 useEffect(() => {
671 if (!environment) return;
672 setPathInput(getAddProjectInitialQuery(environment.baseDirectory));
673 }, [environment]);
674
675 const submitPath = useCallback(async () => {
676 if (!environment || isSubmitting) return;
677 setError(null);
678 const resolved = resolveAddProjectPath({
679 rawPath: pathInput,
680 currentProjectCwd: null,
681 platform: environment.platform,
682 });
683 if (!resolved.ok) {
684 setError(resolved.error);
685 return;
686 }
687
688 setIsSubmitting(true);
689 try {
690 await createProject(resolved.path);
691 } catch (nextError) {
692 setError(errorMessage(nextError));
693 } finally {
694 setIsSubmitting(false);
695 }
696 }, [createProject, environment, isSubmitting, pathInput]);
697
698 return (
699 <AddProjectShell>
700 {error ? <ErrorBanner message={error} /> : null}
701 {environment ? (
702 <>
703 <ProjectPathInput
704 value={pathInput}
705 onChangeText={setPathInput}
706 onSubmit={() => void submitPath()}
707 />
708 <PrimaryActionButton
709 label="Add project"
710 disabled={isSubmitting}
711 onPress={() => void submitPath()}
712 loading={isSubmitting}
713 />
714 <FolderBrowser
715 environment={environment}
716 pathInput={pathInput}
717 setPathInput={setPathInput}
718 />
719 </>
720 ) : (
721 <EmptyEnvironmentState />
722 )}
723 </AddProjectShell>
724 );
725}
726
727export function AddProjectDestinationScreen() {
728 const params = useLocalSearchParams<{
729 environmentId?: string;
730 remoteUrl?: string;
731 repositoryTitle?: string;
732 }>();
733 const environment = useEnvironmentFromParam();
734 const createProject = useCreateProject(environment);
735 const remoteUrl = stringParam(params.remoteUrl);
736 const repositoryTitle = stringParam(params.repositoryTitle);
737 const [pathInput, setPathInput] = useState(() =>
738 getAddProjectInitialQuery(environment?.baseDirectory),
739 );
740 const [isSubmitting, setIsSubmitting] = useState(false);
741 const [error, setError] = useState<string | null>(null);
742
743 useEffect(() => {
744 if (!environment) return;
745 setPathInput(getAddProjectInitialQuery(environment.baseDirectory));
746 }, [environment]);
747
748 const submitPath = useCallback(async () => {
749 if (!environment || !remoteUrl || isSubmitting) return;
750 setError(null);
751 const resolved = resolveAddProjectPath({
752 rawPath: pathInput,
753 currentProjectCwd: null,
754 platform: environment.platform,
755 });
756 if (!resolved.ok) {
757 setError(resolved.error);
758 return;
759 }
760
761 setIsSubmitting(true);
762 try {
763 const client = getEnvironmentClient(environment.environmentId);
764 if (!client) throw new Error("Environment API is not available.");
765 const result = await client.sourceControl.cloneRepository({
766 remoteUrl,
767 destinationPath: resolved.path,
768 });
769 await createProject(result.cwd);
770 } catch (nextError) {
771 setError(errorMessage(nextError));
772 } finally {
773 setIsSubmitting(false);
774 }
775 }, [createProject, environment, isSubmitting, pathInput, remoteUrl]);
776
777 return (
778 <AddProjectShell>
779 {error ? <ErrorBanner message={error} /> : null}
780 {repositoryTitle ? (
781 <View className="rounded-[24px] bg-card px-4 py-3">
782 <Text className="text-[14px] font-t3-bold">{repositoryTitle}</Text>
783 <Text className="mt-0.5 text-[12px] text-foreground-muted" numberOfLines={2}>
784 {remoteUrl}
785 </Text>
786 </View>
787 ) : null}
788 {environment ? (
789 <>
790 <ProjectPathInput
791 value={pathInput}
792 onChangeText={setPathInput}
793 onSubmit={() => void submitPath()}
794 />
795 <PrimaryActionButton
796 label="Clone project"
797 disabled={isSubmitting || !remoteUrl}
798 onPress={() => void submitPath()}
799 loading={isSubmitting}
800 />
801 <FolderBrowser
802 environment={environment}
803 pathInput={pathInput}
804 setPathInput={setPathInput}
805 />
806 </>
807 ) : (
808 <EmptyEnvironmentState />
809 )}
810 </AddProjectShell>
811 );
812}