@@ -4,7 +4,6 @@ import type { WorkspaceSelection } from "@/components/ProjectSidebar";
44import type { ProjectConfig } from "@/config" ;
55
66interface UseWorkspaceManagementProps {
7- projects : Map < string , ProjectConfig > ;
87 selectedWorkspace : WorkspaceSelection | null ;
98 onProjectsUpdate : ( projects : Map < string , ProjectConfig > ) => void ;
109 onSelectedWorkspaceUpdate : ( workspace : WorkspaceSelection | null ) => void ;
@@ -14,7 +13,6 @@ interface UseWorkspaceManagementProps {
1413 * Hook to manage workspace operations (create, remove, rename, list)
1514 */
1615export function useWorkspaceManagement ( {
17- projects,
1816 selectedWorkspace,
1917 onProjectsUpdate,
2018 onSelectedWorkspaceUpdate,
@@ -43,30 +41,21 @@ export function useWorkspaceManagement({
4341 const createWorkspace = async ( projectPath : string , branchName : string ) => {
4442 const result = await window . api . workspace . create ( projectPath , branchName ) ;
4543 if ( result . success ) {
46- // Update the project config with the new workspace
47- const newProjects = new Map ( projects ) ;
48- const projectConfig = newProjects . get ( projectPath ) ;
49- if ( projectConfig ) {
50- projectConfig . workspaces . push ( {
51- path : result . metadata . workspacePath ,
52- } ) ;
53- onProjectsUpdate ( newProjects ) ;
54-
55- await window . api . config . save ( {
56- projects : Array . from ( newProjects . entries ( ) ) ,
57- } ) ;
44+ // Backend has already updated the config - reload projects to get updated state
45+ const projectsList = await window . api . projects . list ( ) ;
46+ const loadedProjects = new Map ( projectsList . map ( ( p ) => [ p . path , p ] ) ) ;
47+ onProjectsUpdate ( loadedProjects ) ;
5848
59- // Reload workspace metadata to get the new workspace ID
60- await loadWorkspaceMetadata ( ) ;
49+ // Reload workspace metadata to get the new workspace ID
50+ await loadWorkspaceMetadata ( ) ;
6151
62- // Return the new workspace selection
63- return {
64- projectPath,
65- projectName : result . metadata . projectName ,
66- workspacePath : result . metadata . workspacePath ,
67- workspaceId : result . metadata . id ,
68- } ;
69- }
52+ // Return the new workspace selection
53+ return {
54+ projectPath,
55+ projectName : result . metadata . projectName ,
56+ workspacePath : result . metadata . workspacePath ,
57+ workspaceId : result . metadata . id ,
58+ } ;
7059 } else {
7160 throw new Error ( result . error ) ;
7261 }
@@ -77,9 +66,9 @@ export function useWorkspaceManagement({
7766 ) : Promise < { success : boolean ; error ?: string } > => {
7867 const result = await window . api . workspace . remove ( workspaceId ) ;
7968 if ( result . success ) {
80- // Reload config since backend has updated it
81- const config = await window . api . config . load ( ) ;
82- const loadedProjects = new Map ( config . projects ) ;
69+ // Backend has already updated the config - reload projects to get updated state
70+ const projectsList = await window . api . projects . list ( ) ;
71+ const loadedProjects = new Map ( projectsList . map ( ( p ) => [ p . path , p ] ) ) ;
8372 onProjectsUpdate ( loadedProjects ) ;
8473
8574 // Reload workspace metadata
@@ -102,9 +91,9 @@ export function useWorkspaceManagement({
10291 ) : Promise < { success : boolean ; error ?: string } > => {
10392 const result = await window . api . workspace . rename ( workspaceId , newName ) ;
10493 if ( result . success ) {
105- // Reload config since backend has updated it
106- const config = await window . api . config . load ( ) ;
107- const loadedProjects = new Map ( config . projects ) ;
94+ // Backend has already updated the config - reload projects to get updated state
95+ const projectsList = await window . api . projects . list ( ) ;
96+ const loadedProjects = new Map ( projectsList . map ( ( p ) => [ p . path , p ] ) ) ;
10897 onProjectsUpdate ( loadedProjects ) ;
10998
11099 // Reload workspace metadata
0 commit comments