Skip to content

Commit 153e627

Browse files
committed
🤖 fix: reconnect New Workspace button
1 parent e74e229 commit 153e627

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/App.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useCallback, useRef } from "react";
1+
import { useEffect, useCallback, useRef } from "react";
22
import "./styles/globals.css";
33
import { useWorkspaceContext } from "./contexts/WorkspaceContext";
44
import { useProjectContext } from "./contexts/ProjectContext";
@@ -44,6 +44,9 @@ function AppInner() {
4444
renameWorkspace,
4545
selectedWorkspace,
4646
setSelectedWorkspace,
47+
pendingNewWorkspaceProject,
48+
beginWorkspaceCreation,
49+
clearPendingWorkspaceCreation,
4750
} = useWorkspaceContext();
4851
const {
4952
projects,
@@ -54,9 +57,6 @@ function AppInner() {
5457
addProject,
5558
} = useProjectContext();
5659

57-
// Track when we're in "new workspace creation" mode (show FirstMessageInput)
58-
const [pendingNewWorkspaceProject, setPendingNewWorkspaceProject] = useState<string | null>(null);
59-
6060
// Auto-collapse sidebar on mobile by default
6161
const isMobile = typeof window !== "undefined" && window.innerWidth <= 768;
6262
const [sidebarCollapsed, setSidebarCollapsed] = usePersistedState("sidebarCollapsed", isMobile);
@@ -72,7 +72,7 @@ function AppInner() {
7272

7373
const startWorkspaceCreation = useStartWorkspaceCreation({
7474
projects,
75-
setPendingNewWorkspaceProject,
75+
beginWorkspaceCreation,
7676
setSelectedWorkspace,
7777
});
7878

@@ -569,13 +569,13 @@ function AppInner() {
569569
telemetry.workspaceCreated(metadata.id);
570570

571571
// Clear pending state
572-
setPendingNewWorkspaceProject(null);
572+
clearPendingWorkspaceCreation();
573573
}}
574574
onCancel={
575575
pendingNewWorkspaceProject
576576
? () => {
577577
// User cancelled workspace creation - clear pending state
578-
setPendingNewWorkspaceProject(null);
578+
clearPendingWorkspaceCreation();
579579
}
580580
: undefined
581581
}

src/contexts/WorkspaceContext.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ describe("WorkspaceContext", () => {
417417
expect(info).toEqual(workspace);
418418
});
419419

420-
test("tracks pending workspace creation state", async () => {
420+
test("beginWorkspaceCreation clears selection and tracks pending state", async () => {
421421
createMockAPI({
422422
workspace: {
423423
list: () => Promise.resolve([]),
@@ -433,10 +433,21 @@ describe("WorkspaceContext", () => {
433433

434434
expect(ctx().pendingNewWorkspaceProject).toBeNull();
435435

436+
act(() => {
437+
ctx().setSelectedWorkspace({
438+
workspaceId: "ws-123",
439+
projectPath: "/alpha",
440+
projectName: "alpha",
441+
namedWorkspacePath: "alpha/ws-123",
442+
});
443+
});
444+
expect(ctx().selectedWorkspace?.workspaceId).toBe("ws-123");
445+
436446
act(() => {
437447
ctx().beginWorkspaceCreation("/alpha");
438448
});
439449
expect(ctx().pendingNewWorkspaceProject).toBe("/alpha");
450+
expect(ctx().selectedWorkspace).toBeNull();
440451

441452
act(() => {
442453
ctx().clearPendingWorkspaceCreation();

src/contexts/WorkspaceContext.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,13 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) {
350350
return metadata;
351351
}, []);
352352

353-
const beginWorkspaceCreation = useCallback((projectPath: string) => {
354-
setPendingNewWorkspaceProject(projectPath);
355-
}, []);
353+
const beginWorkspaceCreation = useCallback(
354+
(projectPath: string) => {
355+
setPendingNewWorkspaceProject(projectPath);
356+
setSelectedWorkspace(null);
357+
},
358+
[setSelectedWorkspace]
359+
);
356360

357361
const clearPendingWorkspaceCreation = useCallback(() => {
358362
setPendingNewWorkspaceProject(null);

src/hooks/useStartWorkspaceCreation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function persistWorkspaceCreationPrefill(
8383

8484
interface UseStartWorkspaceCreationOptions {
8585
projects: Map<string, ProjectConfig>;
86-
setPendingNewWorkspaceProject: (projectPath: string | null) => void;
86+
beginWorkspaceCreation: (projectPath: string) => void;
8787
setSelectedWorkspace: (selection: WorkspaceSelection | null) => void;
8888
}
8989

@@ -100,7 +100,7 @@ function resolveProjectPath(
100100

101101
export function useStartWorkspaceCreation({
102102
projects,
103-
setPendingNewWorkspaceProject,
103+
beginWorkspaceCreation,
104104
setSelectedWorkspace,
105105
}: UseStartWorkspaceCreationOptions) {
106106
const startWorkspaceCreation = useCallback(
@@ -113,10 +113,10 @@ export function useStartWorkspaceCreation({
113113
}
114114

115115
persistWorkspaceCreationPrefill(resolvedProjectPath, detail);
116-
setPendingNewWorkspaceProject(resolvedProjectPath);
116+
beginWorkspaceCreation(resolvedProjectPath);
117117
setSelectedWorkspace(null);
118118
},
119-
[projects, setPendingNewWorkspaceProject, setSelectedWorkspace]
119+
[projects, beginWorkspaceCreation, setSelectedWorkspace]
120120
);
121121

122122
useEffect(() => {

0 commit comments

Comments
 (0)