Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback, useRef } from "react";
import { useEffect, useCallback, useRef } from "react";
import "./styles/globals.css";
import { useWorkspaceContext } from "./contexts/WorkspaceContext";
import { useProjectContext } from "./contexts/ProjectContext";
Expand Down Expand Up @@ -44,6 +44,9 @@ function AppInner() {
renameWorkspace,
selectedWorkspace,
setSelectedWorkspace,
pendingNewWorkspaceProject,
beginWorkspaceCreation,
clearPendingWorkspaceCreation,
} = useWorkspaceContext();
const {
projects,
Expand All @@ -54,9 +57,6 @@ function AppInner() {
addProject,
} = useProjectContext();

// Track when we're in "new workspace creation" mode (show FirstMessageInput)
const [pendingNewWorkspaceProject, setPendingNewWorkspaceProject] = useState<string | null>(null);

// Auto-collapse sidebar on mobile by default
const isMobile = typeof window !== "undefined" && window.innerWidth <= 768;
const [sidebarCollapsed, setSidebarCollapsed] = usePersistedState("sidebarCollapsed", isMobile);
Expand All @@ -72,7 +72,7 @@ function AppInner() {

const startWorkspaceCreation = useStartWorkspaceCreation({
projects,
setPendingNewWorkspaceProject,
beginWorkspaceCreation,
setSelectedWorkspace,
});

Expand Down Expand Up @@ -569,13 +569,13 @@ function AppInner() {
telemetry.workspaceCreated(metadata.id);

// Clear pending state
setPendingNewWorkspaceProject(null);
clearPendingWorkspaceCreation();
}}
onCancel={
pendingNewWorkspaceProject
? () => {
// User cancelled workspace creation - clear pending state
setPendingNewWorkspaceProject(null);
clearPendingWorkspaceCreation();
}
: undefined
}
Expand Down
13 changes: 12 additions & 1 deletion src/contexts/WorkspaceContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ describe("WorkspaceContext", () => {
expect(info).toEqual(workspace);
});

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

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

act(() => {
ctx().setSelectedWorkspace({
workspaceId: "ws-123",
projectPath: "/alpha",
projectName: "alpha",
namedWorkspacePath: "alpha/ws-123",
});
});
expect(ctx().selectedWorkspace?.workspaceId).toBe("ws-123");

act(() => {
ctx().beginWorkspaceCreation("/alpha");
});
expect(ctx().pendingNewWorkspaceProject).toBe("/alpha");
expect(ctx().selectedWorkspace).toBeNull();

act(() => {
ctx().clearPendingWorkspaceCreation();
Expand Down
10 changes: 7 additions & 3 deletions src/contexts/WorkspaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,13 @@ export function WorkspaceProvider(props: WorkspaceProviderProps) {
return metadata;
}, []);

const beginWorkspaceCreation = useCallback((projectPath: string) => {
setPendingNewWorkspaceProject(projectPath);
}, []);
const beginWorkspaceCreation = useCallback(
(projectPath: string) => {
setPendingNewWorkspaceProject(projectPath);
setSelectedWorkspace(null);
},
[setSelectedWorkspace]
);

const clearPendingWorkspaceCreation = useCallback(() => {
setPendingNewWorkspaceProject(null);
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useStartWorkspaceCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function persistWorkspaceCreationPrefill(

interface UseStartWorkspaceCreationOptions {
projects: Map<string, ProjectConfig>;
setPendingNewWorkspaceProject: (projectPath: string | null) => void;
beginWorkspaceCreation: (projectPath: string) => void;
setSelectedWorkspace: (selection: WorkspaceSelection | null) => void;
}

Expand All @@ -100,7 +100,7 @@ function resolveProjectPath(

export function useStartWorkspaceCreation({
projects,
setPendingNewWorkspaceProject,
beginWorkspaceCreation,
setSelectedWorkspace,
}: UseStartWorkspaceCreationOptions) {
const startWorkspaceCreation = useCallback(
Expand All @@ -113,10 +113,10 @@ export function useStartWorkspaceCreation({
}

persistWorkspaceCreationPrefill(resolvedProjectPath, detail);
setPendingNewWorkspaceProject(resolvedProjectPath);
beginWorkspaceCreation(resolvedProjectPath);
setSelectedWorkspace(null);
},
[projects, setPendingNewWorkspaceProject, setSelectedWorkspace]
[projects, beginWorkspaceCreation, setSelectedWorkspace]
);

useEffect(() => {
Expand Down