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

AddProjectScreen.tsx

1,463 lines50.4 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 { suggestAppAccessForRemote } from "./suggestAppAccess";
91import { useAtomQueryRunner } from "../../state/use-atom-query-runner";
92import {
93 useRemoteConnectionStatus,
94 useRemoteEnvironmentRuntime,
95 useSavedRemoteConnections,
96} from "../../state/use-remote-environment-registry";
97import { resolveAddProjectEnvironment } from "./AddProjectScreen.logic";
98import {
99 createNewTaskDraft,
100 setComposerDraftText,
101 waitForComposerDraftsLoaded,
102} from "../../state/use-composer-drafts";
103​
104interface EnvironmentOption {
105 readonly environmentId: EnvironmentId;
106 readonly label: string;
107 readonly platform: string;
108 readonly machine: EnvironmentMachineKind;
109 readonly baseDirectory: string | null;
110 readonly newProjectsRoot: string | null;
111 readonly connectionState: EnvironmentConnectionPhase;
112 readonly connectionError: string | null;
113 readonly connectionErrorTraceId: string | null;
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 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- invalidates the browse navigation coordinator on unmount so in-flight browses do not commit
370 useEffect(
371 () => () => {
372 browseNavigation.invalidate();
373 },
374 [browseNavigation],
375 );
376​
377 return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath };
379​
380function useEnvironmentOptions(
381 selectedEnvironmentId: EnvironmentId | null = null,
382): ReadonlyArray<EnvironmentOption> {
383 const serverConfigByEnvironmentId = useServerConfigs();
384 const { savedConnectionsById } = useSavedRemoteConnections();
385 const { connectedEnvironments } = useRemoteConnectionStatus();
386​
387 return ((): ReadonlyArray<EnvironmentOption> => {
388 const runtimeByEnvironmentId = new Map(
389 connectedEnvironments.map((environment) => [environment.environmentId, environment] as const),
390 );
391 const options = Object.values(savedConnectionsById).map((connection) => {
392 const config = serverConfigByEnvironmentId.get(connection.environmentId);
393 const runtime = runtimeByEnvironmentId.get(connection.environmentId);
394 return {
395 environmentId: connection.environmentId,
396 label: connection.environmentLabel,
397 platform: platformFromOs(config?.environment.platform.os ?? null),
398 machine: resolveEnvironmentMachineKind(config ?? null),
399 baseDirectory: config?.settings.addProjectBaseDirectory ?? null,
400 newProjectsRoot: config?.newProjectsRoot ?? null,
401 connectionState: runtime?.connectionState ?? "available",
402 connectionError: runtime?.connectionError ?? null,
403 connectionErrorTraceId: runtime?.connectionErrorTraceId ?? null,
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 checkPublishedAppAccess = useAtomCommand(sourceControlEnvironment.checkAppAccess, {
1002 reportFailure: false,
1003 reportDefect: false,
1004 });
1005 const publishRepository = useAtomCommand(sourceControlEnvironment.publishRepository, {
1006 reportFailure: false,
1007 });
1008 const discoveryState = useEnvironmentQuery(
1009 environment === null
1010 ? null
1011 : sourceControlEnvironment.discovery({
1012 environmentId: environment.environmentId,
1013 input: {},
1014 }),
1015 );
1016 const publishTargets = getNewProjectPublishTargets(discoveryState.data);
1017 const [name, setName] = useState("");
1018 const [publishes, setPublishes] = useState(false);
1019 const [publishKind, setPublishKind] = useState<SourceControlProviderKind | null>(null);
1020 const publishTarget = getNewProjectPublishTarget(publishTargets, publishKind);
1021 const [isSubmitting, setIsSubmitting] = useState(false);
1022 const [error, setError] = useState<string | null>(null);
1023 const trimmedName = name.trim();
1024 const pathPreview =
1025 environment?.newProjectsRoot != null
1026 ? getNewProjectPathPreview(environment.newProjectsRoot, trimmedName)
1027 : null;
1028​
1029 const showMachines =
1030 environmentOptions.length > 1 || (environment === null && environmentOptions.length > 0);
1031 const machineRows = showMachines ? (
1032 <ListSection>
1033 {environmentOptions.map((option, index) => {
1034 const selected = option.environmentId === environment?.environmentId;
1035 return (
1036 <ListRow
1037 key={option.environmentId}
1038 title={option.label}
1039 icon={
1040 <EnvironmentMachineSymbol
1041 kind={option.machine}
1042 size={Platform.OS === "android" ? 24 : 17}
1043 tintColorClassName="accent-icon"
1044 />
1046 selected={selected}
1047 disabled={isSubmitting}
1048 isFirst={index === 0}
1049 right={
1050 selected ? (
1051 <SymbolView
1052 name="checkmark"
1053 size={Platform.OS === "android" ? 20 : 14}
1054 tintColorClassName="accent-icon"
1055 type="monochrome"
1056 />
1057 ) : null
1059 onPress={() => setSelectedEnvironmentId(option.environmentId)}
1060 />
1061 );
1062 })}
1063 </ListSection>
1064 ) : null;
1065​
1066 // State lags a render behind, so a double tap could start a second create.
1067 const submittingRef = useRef(false);
1068 const submit = async () => {
1069 if (!environment || trimmedName.length === 0 || submittingRef.current) return;
1070 const originRoute = getActiveRoute(navigation);
1071 submittingRef.current = true;
1072 setError(null);
1073 setIsSubmitting(true);
1074 const result = await createNew({
1075 environmentId: environment.environmentId,
1076 input: { name: trimmedName },
1077 });
1078 if (AsyncResult.isFailure(result)) {
1079 submittingRef.current = false;
1080 setIsSubmitting(false);
1081 setError(errorMessage(Cause.squash(result.cause)));
1082 return;
1084 const { projectId, workspaceRoot, commitError } = result.value;
1085 if (commitError !== undefined) {
1086 Dialog.alert("Created without a first commit", commitError);
1088 if (publishes && publishTarget !== null) {
1089 void publishRepository({
1090 environmentId: environment.environmentId,
1091 input: {
1092 cwd: workspaceRoot,
1093 provider: publishTarget.definition.kind,
1094 repository: getNewProjectRepository(publishTarget, workspaceRoot),
1095 visibility: "private",
1096 },
1097 }).then((publishResult) => {
1098 if (AsyncResult.isFailure(publishResult)) {
1099 Dialog.alert(
1100 `Could not create the ${publishTarget.definition.label} repository`,
1101 errorMessage(Cause.squash(publishResult.cause)),
1102 );
1103 } else {
1104 void suggestAppAccessForRemote(
1105 checkPublishedAppAccess,
1106 environment.environmentId,
1107 publishResult.value.remoteUrl,
1108 );
1110 });
1112 // The draft screen resolves its project from the client store, so it
1113 // must not open before the create event has arrived.
1114 const project = await waitForProject(
1115 { environmentId: environment.environmentId, projectId },
1116 15_000,
1117 );
1118 submittingRef.current = false;
1119 setIsSubmitting(false);
1120 if (project === null) {
1121 setName("");
1122 setError(
1123 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1124 );
1125 return;
1127 openNewTaskDraft(
1129 environmentId: environment.environmentId,
1130 projectId,
1131 title: trimmedName,
1132 },
1133 originRoute,
1134 );
1135 };
1136​
1137 return (
1138 <AddProjectShell title="New project">
1139 {error ? <ErrorBanner message={error} /> : null}
1140 {environment ? (
1141 <>
1142 <TextInput
1143 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
1144 value={name}
1145 onChangeText={setName}
1146 autoCorrect={false}
1147 autoFocus
1148 placeholder="Project name"
1149 returnKeyType="done"
1150 onSubmitEditing={() => void submit()}
1151 />
1152 {pathPreview !== null ? (
1153 <Text className="px-1 text-sm leading-snug text-foreground-muted" numberOfLines={2}>
1154 {trimmedName.length > 0
1155 ? `Creates ${pathPreview}`
1156 : `Goes in ${environment.newProjectsRoot}`}
1157 {showMachines ? ` on ${environment.label}` : null}
1158 </Text>
1159 ) : null}
1160 {machineRows}
1161 {publishTarget !== null ? (
1162 <ListSection>
1163 <ListRow
1164 title={`Create private repository on ${publishTarget.definition.label}`}
1165 subtitle={
1166 trimmedName.length > 0 && pathPreview !== null
1167 ? getNewProjectRepository(publishTarget, pathPreview)
1168 : publishTarget.owner
1170 icon={
1171 <SourceControlIcon
1172 icon={publishTarget.definition.icon}
1173 size={Platform.OS === "android" ? 24 : 18}
1174 colorClassName="accent-icon"
1175 />
1177 isFirst
1178 right={
1179 <ThemedSwitch
1180 accessibilityLabel={`Create private repository on ${publishTarget.definition.label}`}
1181 value={publishes}
1182 onValueChange={setPublishes}
1183 />
1185 onPress={() => setPublishes((current) => !current)}
1186 />
1187 {publishes && publishTargets.length > 1
1188 ? publishTargets.map((target) => {
1189 const selected = target.definition.kind === publishTarget.definition.kind;
1190 return (
1191 <ListRow
1192 key={target.definition.kind}
1193 title={target.definition.label}
1194 icon={
1195 <SourceControlIcon
1196 icon={target.definition.icon}
1197 size={Platform.OS === "android" ? 24 : 17}
1198 colorClassName="accent-icon"
1199 />
1201 selected={selected}
1202 disabled={isSubmitting}
1203 right={
1204 selected ? (
1205 <SymbolView
1206 name="checkmark"
1207 size={Platform.OS === "android" ? 20 : 14}
1208 tintColorClassName="accent-icon"
1209 type="monochrome"
1210 />
1211 ) : null
1213 onPress={() => setPublishKind(target.definition.kind)}
1214 />
1215 );
1216 })
1217 : null}
1218 </ListSection>
1219 ) : null}
1220 <PrimaryActionButton
1221 label="Create project"
1222 disabled={isSubmitting || trimmedName.length === 0}
1223 onPress={() => void submit()}
1224 loading={isSubmitting}
1225 />
1226 <ListSection>
1227 <ListRow
1228 title="Add existing project"
1229 subtitle="Open a folder or clone a repository"
1230 icon={
1231 <SymbolView
1232 name="folder.badge.plus"
1233 size={Platform.OS === "android" ? 24 : 17}
1234 tintColorClassName="accent-icon"
1235 type="monochrome"
1236 />
1238 isFirst
1239 onPress={() =>
1240 navigation.canGoBack()
1241 ? navigation.goBack()
1242 : navigation.dispatch(StackActions.replace("AddProject"))
1244 />
1245 </ListSection>
1246 </>
1247 ) : environmentOptions.length > 0 ? (
1248 machineRows
1249 ) : (
1250 <EmptyEnvironmentState />
1251 )}
1252 </AddProjectShell>
1253 );
1255​
1256export function AddProjectLocalFolderScreen(props: { readonly environmentId?: string | string[] }) {
1257 const environment = useEnvironmentFromParam(props.environmentId);
1258 const canCreateProject = useEnvironmentScope(
1259 environment?.environmentId ?? null,
1260 AuthOrchestrationOperateScope,
1261 );
1262 const createProject = useCreateProject(environment);
1263 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
1264 useBrowsePathInput(environment);
1265 const [isSubmitting, setIsSubmitting] = useState(false);
1266 const [error, setError] = useState<string | null>(null);
1267​
1268 const submitPath = async () => {
1269 if (!environment || isBrowseNavigating || isSubmitting) return;
1270 setError(null);
1271 const resolved = resolveAddProjectPath({
1272 rawPath: pathInput,
1273 currentProjectCwd: null,
1274 platform: environment.platform,
1275 });
1276 if (!resolved.ok) {
1277 setError(resolved.error);
1278 return;
1280​
1281 setIsSubmitting(true);
1282 const result = await createProject(resolved.path);
1283 if (result && AsyncResult.isFailure(result)) {
1284 setError(errorMessage(Cause.squash(result.cause)));
1286 setIsSubmitting(false);
1287 };
1288​
1289 return (
1290 <AddProjectShell title="Local folder">
1291 {error ? <ErrorBanner message={error} /> : null}
1292 {environment ? (
1293 <>
1294 {!canCreateProject ? (
1295 <ErrorBanner message="This connection cannot add projects." />
1296 ) : null}
1297 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1298 <PrimaryActionButton
1299 label="Add project"
1300 disabled={!canCreateProject || isBrowseNavigating || isSubmitting}
1301 onPress={submitPath}
1302 loading={isSubmitting}
1303 />
1304 <FolderBrowser
1305 environment={environment}
1306 navigateToBrowsePath={navigateToBrowsePath}
1307 pathInput={pathInput}
1308 setPathInput={setPathInput}
1309 />
1310 </>
1311 ) : (
1312 <EmptyEnvironmentState />
1313 )}
1314 </AddProjectShell>
1315 );
1317​
1318export function AddProjectDestinationScreen(props: {
1319 readonly environmentId?: string | string[];
1320 readonly remoteUrl?: string | string[];
1321 readonly repositoryTitle?: string | string[];
1322 readonly repositoryName?: string | string[];
1323 readonly prompt?: string | string[];
1324}) {
1325 const openNewTaskDraft = useOpenNewTaskDraft();
1326 const startProjectClone = useAtomCommand(sourceControlEnvironment.startProjectClone, {
1327 reportFailure: false,
1328 });
1329 const checkAppAccess = useAtomCommand(sourceControlEnvironment.checkAppAccess, {
1330 reportFailure: false,
1331 reportDefect: false,
1332 });
1333 const navigation = useNavigation();
1334 const environment = useEnvironmentFromParam(props.environmentId);
1335 const canWriteSourceControl = useEnvironmentScope(
1336 environment?.environmentId ?? null,
1337 AuthSourceControlWriteScope,
1338 );
1339 const canCreateProject = useEnvironmentScope(
1340 environment?.environmentId ?? null,
1341 AuthOrchestrationOperateScope,
1342 );
1343 const canCloneProject = canWriteSourceControl && canCreateProject;
1344 const remoteUrl = stringParam(props.remoteUrl);
1345 const repositoryTitle = stringParam(props.repositoryTitle);
1346 const prompt = stringParam(props.prompt);
1347 const repositoryName = stringParam(props.repositoryName)?.trim() ?? "";
1348 const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } = useBrowsePathInput(
1349 environment,
1350 repositoryName,
1351 );
1352 const [isSubmitting, setIsSubmitting] = useState(false);
1353 const [error, setError] = useState<string | null>(null);
1354​
1355 const submitPath = async () => {
1356 if (
1357 !environment ||
1358 !readEnvironmentScope(environment.environmentId, AuthSourceControlWriteScope) ||
1359 !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope) ||
1360 !remoteUrl ||
1361 isBrowseNavigating ||
1362 isSubmitting
1363 ) {
1364 return;
1366 setError(null);
1367 const resolved = resolveAddProjectPath({
1368 rawPath: pathInput,
1369 currentProjectCwd: null,
1370 platform: environment.platform,
1371 });
1372 if (!resolved.ok) {
1373 setError(resolved.error);
1374 return;
1376​
1377 const originRoute = getActiveRoute(navigation);
1378 setIsSubmitting(true);
1379 const projectId = ProjectId.make(uuidv4());
1380 const title = inferProjectTitleFromPath(resolved.path);
1381 const startResult = await startProjectClone({
1382 environmentId: environment.environmentId,
1383 input: {
1384 projectId,
1385 title,
1386 createdAt: new Date().toISOString(),
1387 remoteUrl,
1388 destinationPath: resolved.path,
1389 },
1390 });
1391 if (AsyncResult.isFailure(startResult)) {
1392 setError(errorMessage(Cause.squash(startResult.cause)));
1393 } else {
1394 void suggestAppAccessForRemote(checkAppAccess, environment.environmentId, remoteUrl);
1395 // Wait for the create event; the client store otherwise falls back to the project picker and loses clone controls.
1396 const project = await waitForProject(
1397 { environmentId: environment.environmentId, projectId },
1398 15_000,
1399 );
1400 if (project === null) {
1401 setError(
1402 "The project was created but has not reached this device yet. It will appear in the project list once the connection catches up.",
1403 );
1404 } else {
1405 openNewTaskDraft(
1407 environmentId: environment.environmentId,
1408 projectId,
1409 title,
1410 cloning: "1",
1411 ...(prompt
1412 ? await draftWithPrompt(environment.environmentId, projectId, prompt).then(
1413 (draftId) => ({ draftId }),
1414 () => ({}),
1416 : {}),
1417 },
1418 originRoute,
1419 );
1422 setIsSubmitting(false);
1423 };
1424​
1425 return (
1426 <AddProjectShell title="Clone destination">
1427 {error ? <ErrorBanner message={error} /> : null}
1428 {repositoryTitle ? (
1429 <View className="rounded-[24px] bg-grouped-card px-4 py-3">
1430 <Text className="text-base font-t3-bold">{repositoryTitle}</Text>
1431 <Text className="mt-0.5 text-xs text-foreground-muted" numberOfLines={2}>
1432 {remoteUrl}
1433 </Text>
1434 </View>
1435 ) : null}
1436 {environment ? (
1437 <>
1438 <ProjectPathInput value={pathInput} onChangeText={setPathInput} onSubmit={submitPath} />
1439 <PrimaryActionButton
1440 label="Clone project"
1441 disabled={!canCloneProject || isBrowseNavigating || isSubmitting || !remoteUrl}
1442 onPress={submitPath}
1443 loading={isSubmitting}
1444 />
1445 {!canCloneProject ? (
1446 <Text className="text-sm text-foreground-muted">
1447 This connection cannot clone projects.
1448 </Text>
1449 ) : null}
1450 <FolderBrowser
1451 environment={environment}
1452 navigateToBrowsePath={navigateToBrowsePath}
1453 pathInput={pathInput}
1454 setPathInput={setPathInput}
1455 pinnedDirectoryName={repositoryName}
1456 />
1457 </>
1458 ) : (
1459 <EmptyEnvironmentState />
1460 )}
1461 </AddProjectShell>
1462 );