From 153e627a0f988c1eeb09157b680862587cdc0d30 Mon Sep 17 00:00:00 2001 From: Ammar Date: Sat, 15 Nov 2025 19:37:16 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix:=20reconnect=20New=20Workspa?= =?UTF-8?q?ce=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 14 +++++++------- src/contexts/WorkspaceContext.test.tsx | 13 ++++++++++++- src/contexts/WorkspaceContext.tsx | 10 +++++++--- src/hooks/useStartWorkspaceCreation.ts | 8 ++++---- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0621faec0..5d8f8a905 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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"; @@ -44,6 +44,9 @@ function AppInner() { renameWorkspace, selectedWorkspace, setSelectedWorkspace, + pendingNewWorkspaceProject, + beginWorkspaceCreation, + clearPendingWorkspaceCreation, } = useWorkspaceContext(); const { projects, @@ -54,9 +57,6 @@ function AppInner() { addProject, } = useProjectContext(); - // Track when we're in "new workspace creation" mode (show FirstMessageInput) - const [pendingNewWorkspaceProject, setPendingNewWorkspaceProject] = useState(null); - // Auto-collapse sidebar on mobile by default const isMobile = typeof window !== "undefined" && window.innerWidth <= 768; const [sidebarCollapsed, setSidebarCollapsed] = usePersistedState("sidebarCollapsed", isMobile); @@ -72,7 +72,7 @@ function AppInner() { const startWorkspaceCreation = useStartWorkspaceCreation({ projects, - setPendingNewWorkspaceProject, + beginWorkspaceCreation, setSelectedWorkspace, }); @@ -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 } diff --git a/src/contexts/WorkspaceContext.test.tsx b/src/contexts/WorkspaceContext.test.tsx index bb734a91a..df58f3189 100644 --- a/src/contexts/WorkspaceContext.test.tsx +++ b/src/contexts/WorkspaceContext.test.tsx @@ -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([]), @@ -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(); diff --git a/src/contexts/WorkspaceContext.tsx b/src/contexts/WorkspaceContext.tsx index b7686afa0..5720c2ec2 100644 --- a/src/contexts/WorkspaceContext.tsx +++ b/src/contexts/WorkspaceContext.tsx @@ -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); diff --git a/src/hooks/useStartWorkspaceCreation.ts b/src/hooks/useStartWorkspaceCreation.ts index 3f6b9a389..d67e58c8e 100644 --- a/src/hooks/useStartWorkspaceCreation.ts +++ b/src/hooks/useStartWorkspaceCreation.ts @@ -83,7 +83,7 @@ export function persistWorkspaceCreationPrefill( interface UseStartWorkspaceCreationOptions { projects: Map; - setPendingNewWorkspaceProject: (projectPath: string | null) => void; + beginWorkspaceCreation: (projectPath: string) => void; setSelectedWorkspace: (selection: WorkspaceSelection | null) => void; } @@ -100,7 +100,7 @@ function resolveProjectPath( export function useStartWorkspaceCreation({ projects, - setPendingNewWorkspaceProject, + beginWorkspaceCreation, setSelectedWorkspace, }: UseStartWorkspaceCreationOptions) { const startWorkspaceCreation = useCallback( @@ -113,10 +113,10 @@ export function useStartWorkspaceCreation({ } persistWorkspaceCreationPrefill(resolvedProjectPath, detail); - setPendingNewWorkspaceProject(resolvedProjectPath); + beginWorkspaceCreation(resolvedProjectPath); setSelectedWorkspace(null); }, - [projects, setPendingNewWorkspaceProject, setSelectedWorkspace] + [projects, beginWorkspaceCreation, setSelectedWorkspace] ); useEffect(() => {