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
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function MainApp() {
connectWorkspace,
markWorkspaceConnected,
updateWorkspaceSettings,
removeWorkspace,
hasLoaded,
refreshWorkspaces,
} = useWorkspaces({ onDebug: addDebugEntry });
Expand Down Expand Up @@ -355,6 +356,9 @@ function MainApp() {
onDeleteThread={(workspaceId, threadId) => {
removeThread(workspaceId, threadId);
}}
onDeleteWorkspace={(workspaceId) => {
void removeWorkspace(workspaceId);
}}
/>
<div
className="sidebar-resizer"
Expand Down
19 changes: 19 additions & 0 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SidebarProps = {
onToggleWorkspaceCollapse: (workspaceId: string, collapsed: boolean) => void;
onSelectThread: (workspaceId: string, threadId: string) => void;
onDeleteThread: (workspaceId: string, threadId: string) => void;
onDeleteWorkspace: (workspaceId: string) => void;
};

export function Sidebar({
Expand All @@ -41,6 +42,7 @@ export function Sidebar({
onToggleWorkspaceCollapse,
onSelectThread,
onDeleteThread,
onDeleteWorkspace,
}: SidebarProps) {
const [expandedWorkspaces, setExpandedWorkspaces] = useState(
new Set<string>(),
Expand Down Expand Up @@ -69,6 +71,22 @@ export function Sidebar({
await menu.popup(position, window);
}

async function showWorkspaceMenu(
event: React.MouseEvent,
workspaceId: string,
) {
event.preventDefault();
event.stopPropagation();
const deleteItem = await MenuItem.new({
text: "Delete",
action: () => onDeleteWorkspace(workspaceId),
});
const menu = await Menu.new({ items: [deleteItem] });
const window = getCurrentWindow();
const position = new LogicalPosition(event.clientX, event.clientY);
await menu.popup(position, window);
}

const usagePercent = accountRateLimits?.primary?.usedPercent;
const globalUsagePercent = accountRateLimits?.secondary?.usedPercent;
const credits = accountRateLimits?.credits ?? null;
Expand Down Expand Up @@ -150,6 +168,7 @@ export function Sidebar({
role="button"
tabIndex={0}
onClick={() => onSelectWorkspace(entry.id)}
onContextMenu={(event) => showWorkspaceMenu(event, entry.id)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
Expand Down
45 changes: 45 additions & 0 deletions src/hooks/useWorkspaces.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import type { DebugEntry } from "../types";
import type { WorkspaceInfo, WorkspaceSettings } from "../types";
import { ask } from "@tauri-apps/plugin-dialog";
import {
addWorkspace as addWorkspaceService,
connectWorkspace as connectWorkspaceService,
listWorkspaces,
pickWorkspacePath,
removeWorkspace as removeWorkspaceService,
updateWorkspaceSettings as updateWorkspaceSettingsService,
} from "../services/tauri";

Expand Down Expand Up @@ -149,6 +151,48 @@ export function useWorkspaces(options: UseWorkspacesOptions = {}) {
}
}

async function removeWorkspace(workspaceId: string) {
const workspace = workspaces.find((entry) => entry.id === workspaceId);
const workspaceName = workspace?.name || "this workspace";

const confirmed = await ask(
`Are you sure you want to delete "${workspaceName}"?\n\nThis will remove the workspace from CodexMonitor.`,
{
title: "Delete Workspace",
kind: "warning",
okLabel: "Delete",
cancelLabel: "Cancel",
},
);

if (!confirmed) {
return;
}

onDebug?.({
id: `${Date.now()}-client-remove-workspace`,
timestamp: Date.now(),
source: "client",
label: "workspace/remove",
payload: { workspaceId },
});
try {
await removeWorkspaceService(workspaceId);
setWorkspaces((prev) => prev.filter((entry) => entry.id !== workspaceId));
setActiveWorkspaceId((prev) => (prev === workspaceId ? null : prev));
await refreshWorkspaces();
} catch (error) {
onDebug?.({
id: `${Date.now()}-client-remove-workspace-error`,
timestamp: Date.now(),
source: "error",
label: "workspace/remove error",
payload: error instanceof Error ? error.message : String(error),
});
throw error;
}
}

return {
workspaces,
activeWorkspace,
Expand All @@ -158,6 +202,7 @@ export function useWorkspaces(options: UseWorkspacesOptions = {}) {
connectWorkspace,
markWorkspaceConnected,
updateWorkspaceSettings,
removeWorkspace,
hasLoaded,
refreshWorkspaces,
};
Expand Down
4 changes: 4 additions & 0 deletions src/services/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export async function updateWorkspaceSettings(
return invoke<WorkspaceInfo>("update_workspace_settings", { id, settings });
}

export async function removeWorkspace(id: string): Promise<void> {
return invoke("remove_workspace", { id });
}

export async function connectWorkspace(id: string): Promise<void> {
return invoke("connect_workspace", { id });
}
Expand Down