Skip to content

Commit aacb0c6

Browse files
committed
Fix App.tsx to use correct NewWorkspaceModal props after rebase
1 parent 6482e44 commit aacb0c6

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

src/App.tsx

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ function AppInner() {
149149
);
150150
const [workspaceModalOpen, setWorkspaceModalOpen] = useState(false);
151151
const [workspaceModalProject, setWorkspaceModalProject] = useState<string | null>(null);
152+
const [workspaceModalProjectName, setWorkspaceModalProjectName] = useState<string>("");
153+
const [workspaceModalBranches, setWorkspaceModalBranches] = useState<string[]>([]);
154+
const [workspaceModalDefaultTrunk, setWorkspaceModalDefaultTrunk] = useState<string | undefined>(
155+
undefined
156+
);
157+
const [workspaceModalLoadError, setWorkspaceModalLoadError] = useState<string | null>(null);
158+
const workspaceModalProjectRef = useRef<string | null>(null);
152159
const [sidebarCollapsed, setSidebarCollapsed] = usePersistedState("sidebarCollapsed", false);
153160

154161
const handleToggleSidebar = useCallback(() => {
@@ -311,9 +318,45 @@ function AppInner() {
311318
[removeProject, selectedWorkspace, setSelectedWorkspace]
312319
);
313320

314-
const handleAddWorkspace = useCallback((projectPath: string) => {
321+
const handleAddWorkspace = useCallback(async (projectPath: string) => {
322+
const projectName = projectPath.split("/").pop() ?? projectPath.split("\\").pop() ?? "project";
323+
324+
workspaceModalProjectRef.current = projectPath;
315325
setWorkspaceModalProject(projectPath);
326+
setWorkspaceModalProjectName(projectName);
327+
setWorkspaceModalBranches([]);
328+
setWorkspaceModalDefaultTrunk(undefined);
329+
setWorkspaceModalLoadError(null);
316330
setWorkspaceModalOpen(true);
331+
332+
try {
333+
const branchResult = await window.api.projects.listBranches(projectPath);
334+
335+
// Guard against race condition: only update state if this is still the active project
336+
if (workspaceModalProjectRef.current !== projectPath) {
337+
return;
338+
}
339+
340+
const sanitizedBranches = Array.isArray(branchResult?.branches)
341+
? branchResult.branches.filter((branch): branch is string => typeof branch === "string")
342+
: [];
343+
344+
const recommended =
345+
typeof branchResult?.recommendedTrunk === "string" &&
346+
sanitizedBranches.includes(branchResult.recommendedTrunk)
347+
? branchResult.recommendedTrunk
348+
: sanitizedBranches[0];
349+
350+
setWorkspaceModalBranches(sanitizedBranches);
351+
setWorkspaceModalDefaultTrunk(recommended);
352+
setWorkspaceModalLoadError(null);
353+
} catch (err) {
354+
console.error("Failed to load branches for modal:", err);
355+
const message = err instanceof Error ? err.message : "Unknown error";
356+
setWorkspaceModalLoadError(
357+
`Unable to load branches automatically: ${message}. You can still enter the trunk branch manually.`
358+
);
359+
}
317360
}, []);
318361

319362
// Memoize callbacks to prevent LeftSidebar/ProjectSidebar re-renders
@@ -712,10 +755,18 @@ function AppInner() {
712755
{workspaceModalOpen && workspaceModalProject && (
713756
<NewWorkspaceModal
714757
isOpen={workspaceModalOpen}
715-
projectPath={workspaceModalProject}
758+
projectName={workspaceModalProjectName}
759+
branches={workspaceModalBranches}
760+
defaultTrunkBranch={workspaceModalDefaultTrunk}
761+
loadErrorMessage={workspaceModalLoadError}
716762
onClose={() => {
763+
workspaceModalProjectRef.current = null;
717764
setWorkspaceModalOpen(false);
718765
setWorkspaceModalProject(null);
766+
setWorkspaceModalProjectName("");
767+
setWorkspaceModalBranches([]);
768+
setWorkspaceModalDefaultTrunk(undefined);
769+
setWorkspaceModalLoadError(null);
719770
}}
720771
onAdd={handleCreateWorkspace}
721772
/>

src/services/ipcMain.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ export class IpcMain {
269269
// Block rename during active streaming to prevent race conditions
270270
// (bash processes would have stale cwd, system message would be wrong)
271271
if (this.aiService.isStreaming(workspaceId)) {
272-
return Err("Cannot rename workspace while AI stream is active. Please wait for the stream to complete.");
272+
return Err(
273+
"Cannot rename workspace while AI stream is active. Please wait for the stream to complete."
274+
);
273275
}
274276

275277
// Validate workspace name

tests/ipcMain/renameWorkspace.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,19 @@ describeIntegration("IpcMain rename workspace integration tests", () => {
438438
test.concurrent(
439439
"should fail to rename if workspace is currently streaming",
440440
async () => {
441-
const { env, workspaceId, tempGitRepo, branchName, cleanup } = await setupWorkspace("anthropic");
441+
const { env, workspaceId, tempGitRepo, branchName, cleanup } =
442+
await setupWorkspace("anthropic");
442443
try {
443444
// Add project and workspace to config via IPC
444445
await env.mockIpcRenderer.invoke(IPC_CHANNELS.PROJECT_CREATE, tempGitRepo);
445446
const projectsConfig = env.config.loadConfigOrDefault();
446447
const projectConfig = projectsConfig.projects.get(tempGitRepo);
447448
if (projectConfig) {
448449
const workspacePath = env.config.getWorkspacePath(tempGitRepo, branchName);
449-
projectConfig.workspaces.push({
450+
projectConfig.workspaces.push({
450451
path: workspacePath,
451452
id: workspaceId,
452-
name: branchName
453+
name: branchName,
453454
});
454455
env.config.saveConfig(projectsConfig);
455456
}
@@ -485,5 +486,4 @@ describeIntegration("IpcMain rename workspace integration tests", () => {
485486
},
486487
20000
487488
);
488-
489489
});

0 commit comments

Comments
 (0)