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
53 changes: 53 additions & 0 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { useNativeApi } from "../hooks/useNativeApi";
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
import { toastManager } from "./ui/toast";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";

const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
Expand Down Expand Up @@ -333,6 +334,51 @@ export default function Sidebar() {
[api, dispatch, removeWorktreeMutation, state.projects, state.threads],
);

const handleProjectContextMenu = useCallback(
async (projectId: string, position: { x: number; y: number }) => {
if (!api) return;
const clicked = await api.contextMenu.show([{ id: "delete", label: "Delete" }], position);
if (clicked !== "delete") return;

const project = state.projects.find((entry) => entry.id === projectId);
if (!project) return;

const projectThreads = state.threads.filter((thread) => thread.projectId === projectId);
if (projectThreads.length > 0) {
toastManager.add({
type: "warning",
title: "Project is not empty",
description: "Delete all threads in this project before deleting it.",
});
return;
}

const confirmed = await api.dialogs.confirm(
[`Delete project "${project.name}"?`, "This action cannot be undone."].join("\n"),
);
if (!confirmed) return;

if (isElectron) {
try {
await api.projects.remove({ id: projectId });
} catch (error) {
const message =
error instanceof Error ? error.message : "Unknown error deleting project.";
console.error("Failed to remove project", { projectId, error });
toastManager.add({
type: "error",
title: `Failed to delete "${project.name}"`,
description: message,
});
return;
}
}
Comment on lines +337 to +375

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing confirmation dialog before deleting project. Thread deletion (line 278) uses api.dialogs.confirm to warn users - project deletion should too since it's more destructive (deletes all threads)

Comment thread
coderabbitai[bot] marked this conversation as resolved.

dispatch({ type: "DELETE_PROJECT", projectId });
},
[api, dispatch, state.projects, state.threads],
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
if (!isChatNewShortcut(event, keybindings)) return;
Expand Down Expand Up @@ -413,6 +459,13 @@ export default function Sidebar() {
type="button"
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors duration-150 hover:bg-accent"
onClick={() => dispatch({ type: "TOGGLE_PROJECT", projectId: project.id })}
onContextMenu={(e) => {
e.preventDefault();
void handleProjectContextMenu(project.id, {
x: e.clientX,
y: e.clientY,
});
}}
>
<span className="text-[10px] text-muted-foreground/70">
{project.expanded ? "▼" : "▶"}
Expand Down
45 changes: 45 additions & 0 deletions apps/web/src/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,51 @@ describe("store reducer thread continuity", () => {
expect(next.activeThreadId).toBe("thread-a");
});

it("deletes a project and all of its threads", () => {
const state: AppState = {
projects: [
{
id: "project-1",
name: "One",
cwd: "/tmp/one",
model: "gpt-5.3-codex",
expanded: true,
},
{
id: "project-2",
name: "Two",
cwd: "/tmp/two",
model: "gpt-5.3-codex",
expanded: true,
},
],
threads: [
makeThread({
id: "thread-a",
projectId: "project-1",
}),
makeThread({
id: "thread-b",
projectId: "project-2",
}),
],
activeThreadId: "thread-a",
runtimeMode: "full-access",
diffOpen: false,
};

const next = reducer(state, {
type: "DELETE_PROJECT",
projectId: "project-1",
});

expect(next.projects).toHaveLength(1);
expect(next.projects[0]?.id).toBe("project-2");
expect(next.threads).toHaveLength(1);
expect(next.threads[0]?.id).toBe("thread-b");
expect(next.activeThreadId).toBe("thread-b");
});

it("marks the active thread as visited when selected", () => {
const state = makeState(
makeThread({
Expand Down
20 changes: 20 additions & 0 deletions apps/web/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Action =
| { type: "ADD_PROJECT"; project: Project }
| { type: "SYNC_PROJECTS"; projects: Project[] }
| { type: "TOGGLE_PROJECT"; projectId: string }
| { type: "DELETE_PROJECT"; projectId: string }
| { type: "ADD_THREAD"; thread: Thread }
| { type: "SET_ACTIVE_THREAD"; threadId: string }
| { type: "TOGGLE_THREAD_TERMINAL"; threadId: string }
Expand Down Expand Up @@ -473,6 +474,25 @@ export function reducer(state: AppState, action: Action): AppState {
),
};

case "DELETE_PROJECT": {
const projects = state.projects.filter((project) => project.id !== action.projectId);
if (projects.length === state.projects.length) {
return state;
}

const threads = state.threads.filter((thread) => thread.projectId !== action.projectId);
const activeThreadId = threads.some((thread) => thread.id === state.activeThreadId)
? state.activeThreadId
: (threads[0]?.id ?? null);

return {
...state,
projects,
threads,
activeThreadId,
};
}

case "ADD_THREAD": {
const nextThread = normalizeThreadTerminals({
...action.thread,
Expand Down
Loading