Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c49b8a514 | ||
|
|
f6a0b67e89 | ||
|
|
ebac75593e |
No files matched your search
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
dispatch({ type: "DELETE_PROJECT", projectId });
|
||||
},
|
||||
[api, dispatch, state.projects, state.threads],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const onWindowKeyDown = (event: KeyboardEvent) => {
|
||||
if (!isChatNewShortcut(event, keybindings)) return;
|
||||
@@ -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 ? "▼" : "▶"}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 }
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user