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

AddProjectScreen.tsx

1,471 lines50.6 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 seedPath = getCloneDestinationPath(
296 getAddProjectInitialQuery(environmentBaseDirectory),
297 pinnedDirectoryName,
298 );
299 // Each host keeps the path last typed or browsed for it, and shows its own default until then,
300 // so switching hosts and back loses nothing. With no host selected (one dropping out briefly),
301 // the field keeps the last path typed anywhere.
302 const [paths, setPaths] = useState<{
303 readonly byHost: ReadonlyMap<EnvironmentId, string>;
304 readonly last: string;
305 }>(() => ({ byHost: new Map(), last: seedPath }));
306 const pathInput =
307 environmentId === null ? paths.last : (paths.byHost.get(environmentId) ?? seedPath);
308 const commitPathInput = (path: string) =>
309 setPaths((current) => {
310 const byHost = new Map(current.byHost);
311 if (environmentId !== null) {
312 byHost.set(environmentId, path);
313 }
314 return { byHost, last: path };
315 });
316 const environmentRuntime = useRemoteEnvironmentRuntime(environmentId);
317 const loadBrowsePath = useAtomQueryRunner(filesystemEnvironment.browse, {
318 reportFailure: false,
319 reportDefect: false,
320 });
321 const [browseNavigation] = useState(createBrowseNavigationCoordinator);
322 const [navigatingEnvironmentId, setNavigatingEnvironmentId] = useState<
323 EnvironmentId | null | undefined
324 >(undefined);
325 const isBrowseNavigating = navigatingEnvironmentId === environmentId;
326 const setPathInput = (path: string) => {
327 browseNavigation.invalidate();
328 setNavigatingEnvironmentId(undefined);
329 commitPathInput(path);
330 };
331 const navigateToBrowsePath = async (input: {
332 readonly browseDirectoryPath: string;
333 readonly selectedDirectoryName?: string;
334 }) => {
335 const selectedDirectoryPath = input.selectedDirectoryName
336 ? appendBrowsePathSegment(input.browseDirectoryPath, input.selectedDirectoryName)
337 : input.browseDirectoryPath;
338 const nextPathInput =
339 pinnedDirectoryName && input.selectedDirectoryName
340 ? getCloneDestinationBrowsePath({
341 browseDirectoryPath: input.browseDirectoryPath,
342 selectedDirectoryName: input.selectedDirectoryName,
343 cloneDirectoryName: pinnedDirectoryName,
344 caseSensitive: clonePathCaseSensitive,
345 })
346 : getCloneDestinationPath(selectedDirectoryPath, pinnedDirectoryName);
347 setNavigatingEnvironmentId(environmentId);
348 const committed = await browseNavigation.run(
349 async () => {
350 if (
351 environment &&
352 readEnvironmentScope(environment.environmentId, AuthFilesystemReadScope) &&
353 canPreloadBrowsePath(environmentRuntime?.connectionState)
354 ) {
355 await loadBrowsePath({
356 environmentId: environment.environmentId,
357 input: { partialPath: selectedDirectoryPath },
358 });
359 }
360 },
361 () => commitPathInput(nextPathInput),
362 );
363 if (committed) {
364 setNavigatingEnvironmentId(undefined);
365 }
366 return committed;
367 };
368​
369 useEffect(
370 () => () => {
371 browseNavigation.invalidate();
372 },
373 [browseNavigation],
374 );
375​
376 return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath };
378​
379function useEnvironmentOptions(
380 selectedEnvironmentId: EnvironmentId | null = null,
381): ReadonlyArray<EnvironmentOption> {
382 const serverConfigByEnvironmentId = useServerConfigs();
383 const { savedConnectionsById } = useSavedRemoteConnections();
384 const { connectedEnvironments } = useRemoteConnectionStatus();
385​
386 return ((): ReadonlyArray<EnvironmentOption> => {
387 const runtimeByEnvironmentId = new Map(
388 connectedEnvironments.map((environment) => [environment.environmentId, environment] as const),
389 );
390 const options = Object.values(savedConnectionsById).map((connection) => {
391 const config = serverConfigByEnvironmentId.get(connection.environmentId);
392 const runtime = runtimeByEnvironmentId.get(connection.environmentId);
393 return {
394 environmentId: connection.environmentId,
395 label: connection.environmentLabel,
396 platform: platformFromOs(config?.environment.platform.os ?? null),
397 machine: resolveEnvironmentMachineKind(config ?? null),
398 baseDirectory: config?.settings.addProjectBaseDirectory ?? null,
399 newProjectsRoot: config?.newProjectsRoot ?? null,
400 connectionState: runtime?.connectionState ?? "available",
401 connectionError: runtime?.connectionError ?? null,
402 connectionErrorTraceId: runtime?.connectionErrorTraceId ?? null,
403 supportsCloneTracking: config?.environment.capabilities.projectCloneTracking === true,
404 };
405 });
406 return Arr.sort(
407 options.filter(
408 (environment) =>
409 canCreateProjectInEnvironment(environment.connectionState) ||
410 environment.environmentId === selectedEnvironmentId,
411 ),
412 environmentOptionOrder,
413 );
414 })();
416​
417function useSelectedEnvironment(requestedEnvironmentId: EnvironmentId | null): {
418 readonly environmentOptions: ReadonlyArray<EnvironmentOption>;
419 readonly selectedEnvironment: EnvironmentOption | null;
420 readonly setSelectedEnvironmentId: (environmentId: EnvironmentId) => void;
421} {
422 const [selectedEnvironmentId, setSelectedEnvironmentId] = useState(requestedEnvironmentId);
423 const [previousRequest, setPreviousRequest] = useState(requestedEnvironmentId);
424 if (previousRequest !== requestedEnvironmentId) {
425 setPreviousRequest(requestedEnvironmentId);
426 setSelectedEnvironmentId(requestedEnvironmentId);
427 }
428 const environmentOptions = useEnvironmentOptions(selectedEnvironmentId);
429 const selectedEnvironment =
430 environmentOptions.find((environment) => environment.environmentId === selectedEnvironmentId) ??
431 environmentOptions.find((environment) =>
432 canCreateProjectInEnvironment(environment.connectionState),
433 ) ??
434 null;
435​
436 return {
437 environmentOptions,
438 selectedEnvironment,
439 setSelectedEnvironmentId,
440 };
442​
443function EmptyEnvironmentState() {
444 const navigation = useNavigation();
445​
446 return (
447 <View className="items-center gap-3 rounded-2xl bg-grouped-card px-5 py-8">
448 <Text className="text-center text-lg font-t3-bold">Environment unavailable</Text>
449 <Text className="text-center text-sm leading-normal text-foreground-muted">
450 Start or reconnect an environment before adding a project.
451 </Text>
452 <View className="mt-1">
453 <Button
454 label="Add environment"
455 tone="primary"
456 onPress={() => navigation.dispatch(StackActions.replace("ConnectionsNew"))}
457 />
458 </View>
459 </View>
460 );
462​
463function SourceControlRow(props: {
464 readonly source: AddProjectRemoteSource;
465 readonly selectedEnvironmentId: EnvironmentId;
466 readonly ready: boolean;
467 readonly hint: string;
468 readonly isFirst: boolean;
469}) {
470 const navigation = useNavigation();
471 const title =
472 props.source === "url" ? "Git URL" : `${addProjectRemoteSourceLabel(props.source)} repository`;
473 const subtitle =
474 props.source === "url"
475 ? "Clone from a remote URL"
476 : `Clone ${addProjectRemoteSourceLabel(props.source)} ${props.hint}`;
477 const icon =
478 props.source === "url" ? (
479 <SymbolView
480 name="link"
481 size={Platform.OS === "android" ? 24 : 17}
482 tintColorClassName="accent-icon"
483 type="monochrome"
484 />
485 ) : (
486 <SourceControlIcon
487 icon={sourceControlClients.get(props.source).icon}
488 size={Platform.OS === "android" ? 24 : 18}
489 colorClassName="accent-icon"
490 />
491 );
492​
493 if (!props.ready) {
494 return (
495 <ListRow title={title} subtitle={props.hint} icon={icon} disabled isFirst={props.isFirst} />
496 );
497 }
498​
499 return (
500 <ListRow
501 title={title}
502 subtitle={subtitle}
503 icon={icon}
504 isFirst={props.isFirst}
505 onPress={() =>
506 navigation.dispatch(
507 StackActions.push("AddProjectRepository", {
508 environmentId: props.selectedEnvironmentId,
509 source: props.source,
510 }),
511 )
512 }
513 />
514 );
516​
517export function AddProjectSourceScreen(props: { readonly environmentId?: string | string[] }) {
518 const navigation = useNavigation();
519 const { environmentOptions, selectedEnvironment, setSelectedEnvironmentId } =
520 useSelectedEnvironment(stringParam(props.environmentId) as EnvironmentId | null);
521 const canWriteSourceControl = useEnvironmentScope(
522 selectedEnvironment?.environmentId ?? null,
523 AuthSourceControlWriteScope,
524 );
525 const canCreateProject = useEnvironmentScope(
526 selectedEnvironment?.environmentId ?? null,
527 AuthOrchestrationOperateScope,
528 );
529 const isConnected = canCreateProjectInEnvironment(selectedEnvironment?.connectionState);
530 const canCloneProject = isConnected && canWriteSourceControl && canCreateProject;
531 const discoveryState = useEnvironmentQuery(
532 selectedEnvironment === null || !isConnected
533 ? null
534 : sourceControlEnvironment.discovery({
535 environmentId: selectedEnvironment.environmentId,
536 input: {},
537 }),
538 );
539 const readiness = buildAddProjectRemoteSourceReadiness(discoveryState.data);
540​
541 return (
542 <AddProjectShell title="Add project">
543 {selectedEnvironment === null ? <EmptyEnvironmentState /> : null}
544​
545 {environmentOptions.length > 1 || (selectedEnvironment !== null && !isConnected) ? (
546 <>
547 <SectionTitle>Environments</SectionTitle>
548 <ListSection>
549 {environmentOptions.map((environment, index) => (
550 <ListRow
551 key={environment.environmentId}
552 title={environment.label}
553 subtitle={
554 canCreateProjectInEnvironment(environment.connectionState)
555 ? undefined
556 : connectionStatusText({
557 phase: environment.connectionState,
558 error: environment.connectionError,
559 traceId: environment.connectionErrorTraceId,
560 })
561 }
562 icon={
563 <EnvironmentMachineSymbol
564 kind={environment.machine}
565 size={Platform.OS === "android" ? 24 : 17}
566 tintColorClassName="accent-icon"
567 />
568 }
569 selected={environment.environmentId === selectedEnvironment?.environmentId}
570 disabled={!canCreateProjectInEnvironment(environment.connectionState)}
571 isFirst={index === 0}
572 right={
573 environment.environmentId === selectedEnvironment?.environmentId ? (
574 <SymbolView
575 name="checkmark"
576 size={Platform.OS === "android" ? 20 : 14}
577 tintColorClassName="accent-icon"
578 type="monochrome"
579 />
580 ) : null
581 }
582 onPress={() => setSelectedEnvironmentId(environment.environmentId)}
583 />
584 ))}
585 </ListSection>
586 </>
587 ) : null}
588​
589 {selectedEnvironment ? (
590 <>
591 <ListSection>
592 {selectedEnvironment.newProjectsRoot !== null ? (
593 <ListRow
594 title="New project"
595 subtitle="Start a new Git repository from a name"
596 disabled={!isConnected}
597 icon={
598 <SymbolView
599 name="plus"
600 size={Platform.OS === "android" ? 24 : 17}
601 tintColorClassName="accent-icon"
602 type="monochrome"
603 />
604 }
605 isFirst
606 onPress={() =>
607 navigation.dispatch(
608 StackActions.push("AddProjectNew", {
609 environmentId: selectedEnvironment.environmentId,
610 }),
611 )
612 }
613 />
614 ) : null}
615 <ListRow
616 title="Local folder"
617 subtitle={
618 canCreateProject
619 ? "Browse a folder on disk"
620 : "This connection cannot add projects."
621 }
622 icon={
623 <SymbolView
624 name="folder.badge.plus"
625 size={Platform.OS === "android" ? 24 : 17}
626 tintColorClassName="accent-icon"
627 type="monochrome"
628 />
629 }
630 isFirst={selectedEnvironment.newProjectsRoot === null}
631 disabled={!isConnected || !canCreateProject}
632 onPress={() =>
633 navigation.dispatch(
634 StackActions.push("AddProjectLocal", {
635 environmentId: selectedEnvironment.environmentId,
636 }),
637 )
638 }
639 />
640 {(["url", ...sortAddProjectProviderSources(readiness)] as AddProjectRemoteSource[]).map(
641 (candidate) => (
642 <SourceControlRow
643 key={candidate}
644 source={candidate}
645 selectedEnvironmentId={selectedEnvironment.environmentId}
646 ready={canCloneProject && readiness(candidate).ready}
647 hint={
648 !canCloneProject
649 ? "This connection cannot clone projects."
650 : readiness(candidate).ready
651 ? addProjectRemoteSourcePathHint(candidate)
652 : (readiness(candidate).hint ?? "")
653 }
654 isFirst={false}
655 />
656 ),
657 )}
658 </ListSection>
659 {discoveryState.isPending ? (
660 <AppActivityIndicator colorClassName="accent-icon-muted" />
661 ) : null}
662 </>
663 ) : null}
664 </AddProjectShell>
665 );
667​
668function getActiveRoute(navigation: {
669 getState: () => NavigationState<ParamListBase> | undefined;
670}) {
671 const state = navigation.getState();
672 return state?.routes[state.index];
674​
675function useOpenNewTaskDraft() {
676 const navigation = useNavigation<NativeStackNavigationProp<ReactNavigation.RootParamList>>();
677 const selectDetail = useSelectWorkspaceDetail();
678 return (
679 params: {
680 environmentId: EnvironmentId;
681 projectId: ProjectId;
682 title: string;
683 cloning?: "1";
684 draftId?: string;
685 },
686 originRoute: NavigationState<ParamListBase>["routes"][number] | undefined,
687 ) => {
688 const activeRoute = getActiveRoute(navigation);
689 // A warm link can change the task without replacing its native route key.
690 if (
691 !originRoute ||
692 activeRoute?.key !== originRoute.key ||
693 activeRoute.name !== originRoute.name ||
694 activeRoute.params !== originRoute.params
695 )
696 return;
697 selectDetail({ name: "Thread", params: { draft: params } });
698 };
700​
701async function draftWithPrompt(
702 environmentId: EnvironmentId,
703 projectId: ProjectId,
704 prompt: string,
705): Promise<string> {
706 await waitForComposerDraftsLoaded();
707 const draftId = createNewTaskDraft({ environmentId, projectId });
708 setComposerDraftText(draftId, prompt);
709 return draftId;
711​
712function useCreateProject(environment: EnvironmentOption | null) {
713 const openNewTaskDraft = useOpenNewTaskDraft();
714 const navigation = useNavigation();
715 const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
716 const projects = useProjects();
717​
718 return async (workspaceRoot: string, originRoute = getActiveRoute(navigation)) => {
719 if (
720 !environment ||
721 !canCreateProjectInEnvironment(environment.connectionState) ||
722 !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope)
723 ) {
724 Dialog.alert(
725 "Project not added",
726 `This connection cannot add projects right now. Any existing files remain at ${workspaceRoot}.`,
727 );
728 return;
729 }
730​
731 const existing = findExistingAddProject({
732 projects,
733 environmentId: environment.environmentId,
734 path: workspaceRoot,
735 });
736 if (existing) {
737 Dialog.alert("Project already exists", existing.title);
738 openNewTaskDraft(
739 {
740 environmentId: existing.environmentId,
741 projectId: existing.id,
742 title: existing.title,
743 },
744 originRoute,
745 );
746 return;
747 }
748​
749 const projectId = ProjectId.make(uuidv4());
750 const command = buildProjectCreateCommand({
751 commandId: CommandId.make(uuidv4()),
752 projectId,
753 workspaceRoot,
754 });
755 const result = await createProject({
756 environmentId: environment.environmentId,
757 input: command,
758 });
759 if (AsyncResult.isFailure(result)) {
760 return result;
761 }
762 // A successful command can precede its project in the client store. The
763 // draft treats a missing project as a reason to return to the chooser.
764 const project = await waitForProject(
765 { environmentId: environment.environmentId, projectId },
766 15_000,
767 );
768 if (project === null) {
769 Dialog.alert(
770 "Project added",
771 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
772 );
773 return result;
774 }
775 openNewTaskDraft(
776 {
777 environmentId: environment.environmentId,
778 projectId,
779 title: inferProjectTitleFromPath(workspaceRoot),
780 },
781 originRoute,
782 );
783 return result;
784 };
786​
787function useEnvironmentFromParam(
788 environmentIdParam: string | string[] | undefined,
789): EnvironmentOption | null {
790 const environmentOptions = useEnvironmentOptions();
791 const environmentId = stringParam(environmentIdParam) as EnvironmentId | null;
792 return resolveAddProjectEnvironment(environmentOptions, environmentId);
794​
795export function AddProjectRepositoryScreen(props: {
796 readonly environmentId?: string | string[];
797 readonly source?: string | string[];
798}) {
799 const lookupRepositoryQuery = useAtomQueryRunner(sourceControlEnvironment.repository, {
800 reportFailure: false,
801 });
802 const navigation = useNavigation();
803 const environment = useEnvironmentFromParam(props.environmentId);
804 const source = sourceFromParam(props.source);
805 const [repositoryInput, setRepositoryInput] = useState("");
806 const [isSubmitting, setIsSubmitting] = useState(false);
807 const [error, setError] = useState<string | null>(null);
808​
809 const lookupRepository = async () => {
810 if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return;
811 setError(null);
812 setIsSubmitting(true);
813 const provider = addProjectRemoteSourceProvider(source);
814 if (!provider) {
815 const remoteUrl = normalizePastedCloneUrl(repositoryInput);
816 navigation.dispatch(
817 StackActions.push("AddProjectDestination", {
818 environmentId: environment.environmentId,
819 source,
820 remoteUrl,
821 repositoryTitle: remoteUrl,
822 repositoryName: getCloneDirectoryName(remoteUrl),
823 }),
824 );
825 setIsSubmitting(false);
826 return;
827 }
828​
829 const result = await lookupRepositoryQuery({
830 environmentId: environment.environmentId,
831 input: {
832 provider,
833 repository: repositoryInput.trim(),
834 },
835 });
836 if (AsyncResult.isFailure(result)) {
837 setError(errorMessage(Cause.squash(result.cause)));
838 } else {
839 const repository = result.value;
840 navigation.dispatch(
841 StackActions.push("AddProjectDestination", {
842 environmentId: environment.environmentId,
843 source,
844 remoteUrl: getDefaultCloneUrl(repository),
845 repositoryTitle: repository.nameWithOwner,
846 repositoryName: getCloneDirectoryName(repository.nameWithOwner),
847 }),
848 );
849 }
850 setIsSubmitting(false);
851 };
852​
853 return (
854 <AddProjectShell title={source === "url" ? "Git URL" : addProjectRemoteSourceLabel(source)}>
855 {error ? <ErrorBanner message={error} /> : null}
856 {environment ? (
857 <>
858 <TextInput
859 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
860 value={repositoryInput}
861 onChangeText={setRepositoryInput}
862 autoCapitalize="none"
863 autoCorrect={false}
864 placeholder={
865 source === "url"
866 ? (defaultHostCloneUrl("org/repo") ?? "https://example.com/org/repo.git")
867 : addProjectRemoteSourcePathHint(source)
868 }
869 returnKeyType="next"
870 onSubmitEditing={() => void lookupRepository()}
871 />
872 <PrimaryActionButton
873 label={source === "url" ? "Continue" : "Lookup repository"}
874 disabled={isSubmitting || repositoryInput.trim().length === 0}
875 onPress={() => void lookupRepository()}
876 loading={isSubmitting}
877 />
878 </>
879 ) : (
880 <EmptyEnvironmentState />
881 )}
882 </AddProjectShell>
883 );
885​
886function FolderBrowser(props: {
887 readonly environment: EnvironmentOption;
888 readonly pathInput: string;
889 readonly setPathInput: (path: string) => void;
890 readonly navigateToBrowsePath: (input: {
891 readonly browseDirectoryPath: string;
892 readonly selectedDirectoryName?: string;
893 }) => Promise<boolean>;
894 readonly pinnedDirectoryName?: string;
895}) {
896 const browsePath = getFilesystemBrowsePath(props.pathInput, props.environment.platform);
897 const browseInput =
898 browsePath.directoryPath.length > 0 ? { partialPath: browsePath.directoryPath } : null;
899 const fileAccessSession = useEnvironmentQuery(
900 environmentSession.sessionStateAtom(props.environment.environmentId),
901 );
902 const fileEnvironment = useEnvironmentPresentation(props.environment.environmentId);
903 const fileAccess = resolveFilesystemReadAccess({
904 isCatalogReady: fileEnvironment.isReady,
905 connection: fileEnvironment.presentation?.connection ?? null,
906 session: fileAccessSession.data,
907 sessionError: fileAccessSession.error,
908 });
909 const { canReadFiles } = fileAccess;
910 const browseState = useEnvironmentQuery(
911 !canReadFiles || browseInput === null
912 ? null
913 : filesystemEnvironment.browse({
914 environmentId: props.environment.environmentId,
915 input: browseInput,
916 }),
917 );
918 const pinnedDirectoryName = props.pinnedDirectoryName ?? "";
919 const pinnedDirectoryMatches = isWindowsPlatform(props.environment.platform)
920 ? browsePath.filterQuery.toLowerCase() === pinnedDirectoryName.toLowerCase()
921 : browsePath.filterQuery === pinnedDirectoryName;
922 const browseFilterQuery = pinnedDirectoryMatches ? "" : browsePath.filterQuery;
923 const { visibleEntries: visibleBrowseEntries } = filterFilesystemBrowseEntries(
924 browseState.data?.entries ?? [],
925 browseFilterQuery,
926 );
927​
928 return (
929 <>
930 <SectionTitle>Browse folders</SectionTitle>
931 {!canReadFiles && !fileAccess.isPending ? (
932 <ErrorBanner message={fileAccess.error ?? "This connection cannot browse host folders."} />
933 ) : null}
934 {browseState.error ? <ErrorBanner message={browseState.error} /> : null}
935 <ListSection>
936 {fileAccess.isPending || (browseState.isPending && browseState.data === null) ? (
937 <View className="items-center py-5">
938 <AppActivityIndicator colorClassName="accent-icon-muted" />
939 </View>
940 ) : null}
941 {browsePath.canBrowseUp ? (
942 <ListRow
943 title=".."
944 icon={
945 <SymbolView
946 name="arrow.turn.left.up"
947 size={Platform.OS === "android" ? 24 : 17}
948 tintColorClassName="accent-icon-muted"
949 type="monochrome"
950 />
951 }
952 isFirst
953 right={null}
954 onPress={() => {
955 if (browsePath.parentPath) {
956 void props.navigateToBrowsePath({
957 browseDirectoryPath: browsePath.parentPath,
958 });
959 }
960 }}
961 />
962 ) : null}
963 {visibleBrowseEntries.map((entry, index) => (
964 <ListRow
965 key={entry.fullPath}
966 title={entry.name}
967 icon={
968 <SymbolView
969 name="folder"
970 size={Platform.OS === "android" ? 24 : 17}
971 tintColorClassName="accent-icon-muted"
972 type="monochrome"
973 />
974 }
975 isFirst={index === 0 && !browsePath.canBrowseUp}
976 right={null}
977 onPress={() => {
978 void props.navigateToBrowsePath({
979 browseDirectoryPath: browsePath.directoryPath,
980 selectedDirectoryName: entry.name,
981 });
982 }}
983 />
984 ))}
985 </ListSection>
986 </>
987 );
989​
990export function AddProjectNewScreen(props: { readonly environmentId?: string | string[] }) {
991 const openNewTaskDraft = useOpenNewTaskDraft();
992 const navigation = useNavigation();
993 const environmentOptions = useEnvironmentOptions().filter(
994 (option) => option.newProjectsRoot !== null,
995 );
996 const [selectedEnvironmentId, setSelectedEnvironmentId] = useState(
997 () => stringParam(props.environmentId) as EnvironmentId | null,
998 );
999 const environment = resolveAddProjectEnvironment(environmentOptions, selectedEnvironmentId);
1000 const createNew = useAtomCommand(projectEnvironment.createNew, { reportFailure: false });
1001 const publishRepository = useAtomCommand(sourceControlEnvironment.publishRepository, {
1002 reportFailure: false,
1003 });
1004 const discoveryState = useEnvironmentQuery(
1005 environment === null
1006 ? null
1007 : sourceControlEnvironment.discovery({
1008 environmentId: environment.environmentId,
1009 input: {},
1010 }),
1011 );
1012 const publishTargets = getNewProjectPublishTargets(discoveryState.data);
1013 const [name, setName] = useState("");
1014 const [publishes, setPublishes] = useState(false);
1015 const [publishKind, setPublishKind] = useState<SourceControlProviderKind | null>(null);
1016 const publishTarget = getNewProjectPublishTarget(publishTargets, publishKind);
1017 const [isSubmitting, setIsSubmitting] = useState(false);
1018 const [error, setError] = useState<string | null>(null);
1019 const trimmedName = name.trim();
1020 const pathPreview =
1021 environment?.newProjectsRoot != null
1022 ? getNewProjectPathPreview(environment.newProjectsRoot, trimmedName)
1023 : null;
1024​
1025 const showMachines =
1026 environmentOptions.length > 1 || (environment === null && environmentOptions.length > 0);
1027 const machineRows = showMachines ? (
1028 <ListSection>
1029 {environmentOptions.map((option, index) => {
1030 const selected = option.environmentId === environment?.environmentId;
1031 return (
1032 <ListRow
1033 key={option.environmentId}
1034 title={option.label}
1035 icon={
1036 <EnvironmentMachineSymbol
1037 kind={option.machine}
1038 size={Platform.OS === "android" ? 24 : 17}
1039 tintColorClassName="accent-icon"
1040 />
1042 selected={selected}
1043 disabled={isSubmitting}
1044 isFirst={index === 0}
1045 right={
1046 selected ? (
1047 <SymbolView
1048 name="checkmark"
1049 size={Platform.OS === "android" ? 20 : 14}
1050 tintColorClassName="accent-icon"
1051 type="monochrome"
1052 />
1053 ) : null
1055 onPress={() => setSelectedEnvironmentId(option.environmentId)}
1056 />
1057 );
1058 })}
1059 </ListSection>
1060 ) : null;
1061​
1062 // State lags a render behind, so a double tap could start a second create.
1063 const submittingRef = useRef(false);
1064 const submit = async () => {
1065 if (!environment || trimmedName.length === 0 || submittingRef.current) return;
1066 const originRoute = getActiveRoute(navigation);
1067 submittingRef.current = true;
1068 setError(null);
1069 setIsSubmitting(true);
1070 const result = await createNew({
1071 environmentId: environment.environmentId,
1072 input: { name: trimmedName },
1073 });
1074 if (AsyncResult.isFailure(result)) {
1075 submittingRef.current = false;
1076 setIsSubmitting(false);
1077 setError(errorMessage(Cause.squash(result.cause)));
1078 return;
1080 const { projectId, workspaceRoot, commitError } = result.value;
1081 if (commitError !== undefined) {
1082 Dialog.alert("Created without a first commit", commitError);
1084 if (publishes && publishTarget !== null) {
1085 void publishRepository({
1086 environmentId: environment.environmentId,
1087 input: {
1088 cwd: workspaceRoot,
1089 provider: publishTarget.definition.kind,
1090 repository: getNewProjectRepository(publishTarget, workspaceRoot),
1091 visibility: "private",
1092 },
1093 }).then((publishResult) => {
1094 if (AsyncResult.isFailure(publishResult)) {
1095 Dialog.alert(
1096 `Could not create the ${publishTarget.definition.label} repository`,
1097 errorMessage(Cause.squash(publishResult.cause)),
1098 );
1100 });
1102 // The draft screen resolves its project from the client store, so it
1103 // must not open before the create event has arrived.
1104 const project = await waitForProject(
1105 { environmentId: environment.environmentId, projectId },
1106 15_000,
1107 );
1108 submittingRef.current = false;
1109 setIsSubmitting(false);
1110 if (project === null) {
1111 setName("");
1112 setError(
1113 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1114 );
1115 return;
1117 openNewTaskDraft(
1119 environmentId: environment.environmentId,
1120 projectId,
1121 title: trimmedName,
1122 },
1123 originRoute,
1124 );
1125 };
1126​
1127 return (
1128 <AddProjectShell title="New project">
1129 {error ? <ErrorBanner message={error} /> : null}
1130 {environment ? (
1131 <>
1132 <TextInput
1133 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
1134 value={name}
1135 onChangeText={setName}
1136 autoCorrect={false}
1137 autoFocus
1138 placeholder="Project name"
1139 returnKeyType="done"
1140 onSubmitEditing={() => void submit()}
1141 />
1142 {pathPreview !== null ? (
1143 <Text className="px-1 text-sm leading-snug text-foreground-muted" numberOfLines={2}>
1144 {trimmedName.length > 0
1145 ? `Creates ${pathPreview}`
1146 : `Goes in ${environment.newProjectsRoot}`}
1147 {showMachines ? ` on ${environment.label}` : null}
1148 </Text>
1149 ) : null}
1150 {machineRows}
1151 {publishTarget !== null ? (
1152 <ListSection>
1153 <ListRow
1154 title={`Create private repository on ${publishTarget.definition.label}`}
1155 subtitle={
1156 trimmedName.length > 0 && pathPreview !== null
1157 ? getNewProjectRepository(publishTarget, pathPreview)
1158 : publishTarget.owner
1160 icon={
1161 <SourceControlIcon
1162 icon={publishTarget.definition.icon}
1163 size={Platform.OS === "android" ? 24 : 18}
1164 colorClassName="accent-icon"
1165 />
1167 isFirst
1168 right={
1169 <ThemedSwitch
1170 accessibilityLabel={`Create private repository on ${publishTarget.definition.label}`}
1171 value={publishes}
1172 onValueChange={setPublishes}
1173 />
1175 onPress={() => setPublishes((current) => !current)}
1176 />
1177 {publishes && publishTargets.length > 1
1178 ? publishTargets.map((target) => {
1179 const selected = target.definition.kind === publishTarget.definition.kind;
1180 return (
1181 <ListRow
1182 key={target.definition.kind}
1183 title={target.definition.label}
1184 icon={
1185 <SourceControlIcon
1186 icon={target.definition.icon}
1187 size={Platform.OS === "android" ? 24 : 17}
1188 colorClassName="accent-icon"
1189 />
1191 selected={selected}
1192 disabled={isSubmitting}
1193 right={
1194 selected ? (
1195 <SymbolView
1196 name="checkmark"
1197 size={Platform.OS === "android" ? 20 : 14}
1198 tintColorClassName="accent-icon"
1199 type="monochrome"
1200 />
1201 ) : null
1203 onPress={() => setPublishKind(target.definition.kind)}
1204 />
1205 );
1206 })
1207 : null}
1208 </ListSection>
1209 ) : null}
1210 <PrimaryActionButton
1211 label="Create project"
1212 disabled={isSubmitting || trimmedName.length === 0}
1213 onPress={() => void submit()}
1214 loading={isSubmitting}
1215 />
1216 <ListSection>
1217 <ListRow
1218 title="Add existing project"
1219 subtitle="Open a folder or clone a repository"
1220 icon={
1221 <SymbolView
1222 name="folder.badge.plus"
1223 size={Platform.OS === "android" ? 24 : 17}
1224 tintColorClassName="accent-icon"
1225 type="monochrome"
1226 />
1228 isFirst
1229 onPress={() =>
1230 navigation.canGoBack()
1231 ? navigation.goBack()
1232 : navigation.dispatch(StackActions.replace("AddProject"))
1234 />
1235 </ListSection>
1236 </>
1237 ) : environmentOptions.length > 0 ? (
1238 machineRows
1239 ) : (
1240 <EmptyEnvironmentState />
1241 )}
1242 </AddProjectShell>
1243 );
1245​
1246export function AddProjectLocalFolderScreen(props: { readonly environmentId?: string | string[] }) {
1247 const environment = useEnvironmentFromParam(props.environmentId);
1248 const canCreateProject = useEnvironmentScope(
1249 environment?.environmentId ?? null,
1250 AuthOrchestrationOperateScope,
1251 );
1252 const createProject = useCreateProject(environment);
1253 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
1254 useBrowsePathInput(environment);
1255 const [isSubmitting, setIsSubmitting] = useState(false);
1256 const [error, setError] = useState<string | null>(null);
1257​
1258 const submitPath = async () => {
1259 if (!environment || isBrowseNavigating || isSubmitting) return;
1260 setError(null);
1261 const resolved = resolveAddProjectPath({
1262 rawPath: pathInput,
1263 currentProjectCwd: null,
1264 platform: environment.platform,
1265 });
1266 if (!resolved.ok) {
1267 setError(resolved.error);
1268 return;
1270​
1271 setIsSubmitting(true);
1272 const result = await createProject(resolved.path);
1273 if (result && AsyncResult.isFailure(result)) {
1274 setError(errorMessage(Cause.squash(result.cause)));
1276 setIsSubmitting(false);
1277 };
1278​
1279 return (
1280 <AddProjectShell title="Local folder">
1281 {error ? <ErrorBanner message={error} /> : null}
1282 {environment ? (
1283 <>
1284 {!canCreateProject ? (
1285 <ErrorBanner message="This connection cannot add projects." />
1286 ) : null}
1287 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1288 <PrimaryActionButton
1289 label="Add project"
1290 disabled={!canCreateProject || isBrowseNavigating || isSubmitting}
1291 onPress={submitPath}
1292 loading={isSubmitting}
1293 />
1294 <FolderBrowser
1295 environment={environment}
1296 navigateToBrowsePath={navigateToBrowsePath}
1297 pathInput={pathInput}
1298 setPathInput={setPathInput}
1299 />
1300 </>
1301 ) : (
1302 <EmptyEnvironmentState />
1303 )}
1304 </AddProjectShell>
1305 );
1307​
1308export function AddProjectDestinationScreen(props: {
1309 readonly environmentId?: string | string[];
1310 readonly remoteUrl?: string | string[];
1311 readonly repositoryTitle?: string | string[];
1312 readonly repositoryName?: string | string[];
1313 readonly prompt?: string | string[];
1314}) {
1315 const openNewTaskDraft = useOpenNewTaskDraft();
1316 const cloneRepository = useAtomCommand(sourceControlEnvironment.cloneRepository, {
1317 reportFailure: false,
1318 });
1319 const startProjectClone = useAtomCommand(sourceControlEnvironment.startProjectClone, {
1320 reportFailure: false,
1321 });
1322 const navigation = useNavigation();
1323 const environment = useEnvironmentFromParam(props.environmentId);
1324 const canWriteSourceControl = useEnvironmentScope(
1325 environment?.environmentId ?? null,
1326 AuthSourceControlWriteScope,
1327 );
1328 const canCreateProject = useEnvironmentScope(
1329 environment?.environmentId ?? null,
1330 AuthOrchestrationOperateScope,
1331 );
1332 const canCloneProject = canWriteSourceControl && canCreateProject;
1333 const createProject = useCreateProject(environment);
1334 const remoteUrl = stringParam(props.remoteUrl);
1335 const repositoryTitle = stringParam(props.repositoryTitle);
1336 const prompt = stringParam(props.prompt);
1337 const repositoryName = stringParam(props.repositoryName)?.trim() ?? "";
1338 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } = useBrowsePathInput(
1339 environment,
1340 repositoryName,
1341 );
1342 const [isSubmitting, setIsSubmitting] = useState(false);
1343 const [error, setError] = useState<string | null>(null);
1344​
1345 const submitPath = async () => {
1346 if (
1347 !environment ||
1348 !readEnvironmentScope(environment.environmentId, AuthSourceControlWriteScope) ||
1349 !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope) ||
1350 !remoteUrl ||
1351 isBrowseNavigating ||
1352 isSubmitting
1353 ) {
1354 return;
1356 setError(null);
1357 const resolved = resolveAddProjectPath({
1358 rawPath: pathInput,
1359 currentProjectCwd: null,
1360 platform: environment.platform,
1361 });
1362 if (!resolved.ok) {
1363 setError(resolved.error);
1364 return;
1366​
1367 const originRoute = getActiveRoute(navigation);
1368 setIsSubmitting(true);
1369 if (environment.supportsCloneTracking) {
1370 const projectId = ProjectId.make(uuidv4());
1371 const title = inferProjectTitleFromPath(resolved.path);
1372 const startResult = await startProjectClone({
1373 environmentId: environment.environmentId,
1374 input: {
1375 projectId,
1376 title,
1377 createdAt: new Date().toISOString(),
1378 remoteUrl,
1379 destinationPath: resolved.path,
1380 },
1381 });
1382 if (AsyncResult.isFailure(startResult)) {
1383 setError(errorMessage(Cause.squash(startResult.cause)));
1384 } else {
1385 // Wait for the create event; the client store otherwise falls back to the project picker and loses clone controls.
1386 const project = await waitForProject(
1387 { environmentId: environment.environmentId, projectId },
1388 15_000,
1389 );
1390 if (project === null) {
1391 setError(
1392 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1393 );
1394 } else {
1395 openNewTaskDraft(
1397 environmentId: environment.environmentId,
1398 projectId,
1399 title,
1400 cloning: "1",
1401 ...(prompt
1402 ? await draftWithPrompt(environment.environmentId, projectId, prompt).then(
1403 (draftId) => ({ draftId }),
1404 () => ({}),
1406 : {}),
1407 },
1408 originRoute,
1409 );
1412 setIsSubmitting(false);
1413 return;
1415 const cloneResult = await cloneRepository({
1416 environmentId: environment.environmentId,
1417 input: {
1418 remoteUrl,
1419 destinationPath: resolved.path,
1420 },
1421 });
1422 if (AsyncResult.isFailure(cloneResult)) {
1423 setError(errorMessage(Cause.squash(cloneResult.cause)));
1424 } else {
1425 const createResult = await createProject(cloneResult.value.cwd, originRoute);
1426 if (createResult && AsyncResult.isFailure(createResult)) {
1427 setError(errorMessage(Cause.squash(createResult.cause)));
1430 setIsSubmitting(false);
1431 };
1432​
1433 return (
1434 <AddProjectShell title="Clone destination">
1435 {error ? <ErrorBanner message={error} /> : null}
1436 {repositoryTitle ? (
1437 <View className="rounded-[24px] bg-grouped-card px-4 py-3">
1438 <Text className="text-base font-t3-bold">{repositoryTitle}</Text>
1439 <Text className="mt-0.5 text-xs text-foreground-muted" numberOfLines={2}>
1440 {remoteUrl}
1441 </Text>
1442 </View>
1443 ) : null}
1444 {environment ? (
1445 <>
1446 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1447 <PrimaryActionButton
1448 label="Clone project"
1449 disabled={!canCloneProject || isBrowseNavigating || isSubmitting || !remoteUrl}
1450 onPress={submitPath}
1451 loading={isSubmitting}
1452 />
1453 {!canCloneProject ? (
1454 <Text className="text-sm text-foreground-muted">
1455 This connection cannot clone projects.
1456 </Text>
1457 ) : null}
1458 <FolderBrowser
1459 environment={environment}
1460 navigateToBrowsePath={navigateToBrowsePath}
1461 pathInput={pathInput}
1462 setPathInput={setPathInput}
1463 pinnedDirectoryName={repositoryName}
1464 />
1465 </>
1466 ) : (
1467 <EmptyEnvironmentState />
1468 )}
1469 </AddProjectShell>
1470 );