11import { useCallback , useEffect , useMemo , useState } from "react" ;
22import type { DebugEntry } from "../types" ;
33import type { WorkspaceInfo , WorkspaceSettings } from "../types" ;
4+ import { ask } from "@tauri-apps/plugin-dialog" ;
45import {
56 addWorkspace as addWorkspaceService ,
67 connectWorkspace as connectWorkspaceService ,
78 listWorkspaces ,
89 pickWorkspacePath ,
10+ removeWorkspace as removeWorkspaceService ,
911 updateWorkspaceSettings as updateWorkspaceSettingsService ,
1012} from "../services/tauri" ;
1113
@@ -149,6 +151,48 @@ export function useWorkspaces(options: UseWorkspacesOptions = {}) {
149151 }
150152 }
151153
154+ async function removeWorkspace ( workspaceId : string ) {
155+ const workspace = workspaces . find ( ( entry ) => entry . id === workspaceId ) ;
156+ const workspaceName = workspace ?. name || "this workspace" ;
157+
158+ const confirmed = await ask (
159+ `Are you sure you want to delete "${ workspaceName } "?\n\nThis will remove the workspace from CodexMonitor.` ,
160+ {
161+ title : "Delete Workspace" ,
162+ kind : "warning" ,
163+ okLabel : "Delete" ,
164+ cancelLabel : "Cancel" ,
165+ } ,
166+ ) ;
167+
168+ if ( ! confirmed ) {
169+ return ;
170+ }
171+
172+ onDebug ?.( {
173+ id : `${ Date . now ( ) } -client-remove-workspace` ,
174+ timestamp : Date . now ( ) ,
175+ source : "client" ,
176+ label : "workspace/remove" ,
177+ payload : { workspaceId } ,
178+ } ) ;
179+ try {
180+ await removeWorkspaceService ( workspaceId ) ;
181+ setWorkspaces ( ( prev ) => prev . filter ( ( entry ) => entry . id !== workspaceId ) ) ;
182+ setActiveWorkspaceId ( ( prev ) => ( prev === workspaceId ? null : prev ) ) ;
183+ await refreshWorkspaces ( ) ;
184+ } catch ( error ) {
185+ onDebug ?.( {
186+ id : `${ Date . now ( ) } -client-remove-workspace-error` ,
187+ timestamp : Date . now ( ) ,
188+ source : "error" ,
189+ label : "workspace/remove error" ,
190+ payload : error instanceof Error ? error . message : String ( error ) ,
191+ } ) ;
192+ throw error ;
193+ }
194+ }
195+
152196 return {
153197 workspaces,
154198 activeWorkspace,
@@ -158,6 +202,7 @@ export function useWorkspaces(options: UseWorkspacesOptions = {}) {
158202 connectWorkspace,
159203 markWorkspaceConnected,
160204 updateWorkspaceSettings,
205+ removeWorkspace,
161206 hasLoaded,
162207 refreshWorkspaces,
163208 } ;
0 commit comments