Skip to content

Commit 84ceb13

Browse files
Zandor300claude
andcommitted
fix(mobile): open the existing project when adding a duplicate path
Adding a project by URL failed with "Destination path already exists and is not empty" when the chosen destination was already a T3 Code project, and the local folder flow popped a "Project already exists" alert before navigating. Both flows now look the path up first and hand off to the existing project's new-task draft, so the user just starts prompting. This matches how the web command palette already handles a duplicate path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 2aa5f09 commit 84ceb13

1 file changed

Lines changed: 43 additions & 25 deletions

File tree

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { CommandId, type EnvironmentId, ProjectId } from "@t3tools/contracts";
3333
import { CommonActions, StackActions, useNavigation } from "@react-navigation/native";
3434
import { SymbolView } from "../../components/AppSymbol";
3535
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
36-
import { ActivityIndicator, Alert, Pressable, ScrollView, View } from "react-native";
36+
import { ActivityIndicator, Pressable, ScrollView, View } from "react-native";
3737
import { useSafeAreaInsets } from "react-native-safe-area-context";
3838
import * as Arr from "effect/Array";
3939
import * as Cause from "effect/Cause";
@@ -565,39 +565,52 @@ export function AddProjectSourceScreen() {
565565
);
566566
}
567567

568-
function useCreateProject(environment: EnvironmentOption | null) {
568+
// Adding a path the environment already tracks should feel like picking that
569+
// project from the list, so callers hand off to its draft instead of failing.
570+
// Returns whether the path matched an existing project.
571+
function useOpenExistingProject(environment: EnvironmentOption | null) {
569572
const navigation = useNavigation();
570-
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
571573
const projects = useProjects();
572574

573575
return useCallback(
574-
async (workspaceRoot: string) => {
575-
if (!environment || !canCreateProjectInEnvironment(environment.connectionState)) return;
576-
576+
(workspaceRoot: string) => {
577+
if (!environment) return false;
577578
const existing = findExistingAddProject({
578579
projects,
579580
environmentId: environment.environmentId,
580581
path: workspaceRoot,
581582
});
582-
if (existing) {
583-
Alert.alert("Project already exists", existing.title);
584-
navigation.dispatch(
585-
CommonActions.reset({
586-
index: 0,
587-
routes: [
588-
{
589-
name: "NewTaskDraft",
590-
params: {
591-
environmentId: existing.environmentId,
592-
projectId: existing.id,
593-
title: existing.title,
594-
},
583+
if (!existing) return false;
584+
navigation.dispatch(
585+
CommonActions.reset({
586+
index: 0,
587+
routes: [
588+
{
589+
name: "NewTaskDraft",
590+
params: {
591+
environmentId: existing.environmentId,
592+
projectId: existing.id,
593+
title: existing.title,
595594
},
596-
],
597-
}),
598-
);
599-
return;
600-
}
595+
},
596+
],
597+
}),
598+
);
599+
return true;
600+
},
601+
[environment, navigation, projects],
602+
);
603+
}
604+
605+
function useCreateProject(environment: EnvironmentOption | null) {
606+
const navigation = useNavigation();
607+
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
608+
const openExistingProject = useOpenExistingProject(environment);
609+
610+
return useCallback(
611+
async (workspaceRoot: string) => {
612+
if (!environment || !canCreateProjectInEnvironment(environment.connectionState)) return;
613+
if (openExistingProject(workspaceRoot)) return;
601614

602615
const projectId = ProjectId.make(uuidv4());
603616
const command = buildProjectCreateCommand({
@@ -630,7 +643,7 @@ function useCreateProject(environment: EnvironmentOption | null) {
630643
);
631644
return result;
632645
},
633-
[createProject, environment, projects, navigation],
646+
[createProject, environment, navigation, openExistingProject],
634647
);
635648
}
636649

@@ -894,6 +907,7 @@ export function AddProjectDestinationScreen(props: {
894907
});
895908
const environment = useEnvironmentFromParam(props.environmentId);
896909
const createProject = useCreateProject(environment);
910+
const openExistingProject = useOpenExistingProject(environment);
897911
const remoteUrl = stringParam(props.remoteUrl);
898912
const repositoryTitle = stringParam(props.repositoryTitle);
899913
// A lookup derives this from "owner/repo", a pasted clone URL from its own
@@ -920,6 +934,9 @@ export function AddProjectDestinationScreen(props: {
920934
setError(resolved.error);
921935
return;
922936
}
937+
// Cloning into a directory that is already a project would fail on a
938+
// non-empty destination, so open that project instead of reporting it.
939+
if (openExistingProject(resolved.path)) return;
923940

924941
setIsSubmitting(true);
925942
const cloneResult = await cloneRepository({
@@ -944,6 +961,7 @@ export function AddProjectDestinationScreen(props: {
944961
environment,
945962
isBrowseNavigating,
946963
isSubmitting,
964+
openExistingProject,
947965
pathInput,
948966
remoteUrl,
949967
]);

0 commit comments

Comments
 (0)