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
33 changes: 33 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "./styles/compact-tablet.css";
import successSoundUrl from "./assets/success-notification.mp3";
import errorSoundUrl from "./assets/error-notification.mp3";
import { WorktreePrompt } from "./features/workspaces/components/WorktreePrompt";
import { RenameThreadPrompt } from "./features/threads/components/RenameThreadPrompt";
import { AboutView } from "./features/about/components/AboutView";
import { SettingsView } from "./features/settings/components/SettingsView";
import { DesktopLayout } from "./features/layout/components/DesktopLayout";
Expand Down Expand Up @@ -72,6 +73,7 @@ import { useDictationModel } from "./features/dictation/hooks/useDictationModel"
import { useDictation } from "./features/dictation/hooks/useDictation";
import { useHoldToDictate } from "./features/dictation/hooks/useHoldToDictate";
import { useQueuedSend } from "./features/threads/hooks/useQueuedSend";
import { useRenameThreadPrompt } from "./features/threads/hooks/useRenameThreadPrompt";
import { useWorktreePrompt } from "./features/workspaces/hooks/useWorktreePrompt";
import { useUiScaleShortcuts } from "./features/layout/hooks/useUiScaleShortcuts";
import { useWorkspaceSelection } from "./features/workspaces/hooks/useWorkspaceSelection";
Expand Down Expand Up @@ -592,6 +594,7 @@ function MainApp() {
lastAgentMessageByThread,
interruptTurn,
removeThread,
renameThread,
startThreadForWorkspace,
listThreadsForWorkspace,
loadOlderThreadsForWorkspace,
Expand All @@ -616,6 +619,24 @@ function MainApp() {
onDebug: addDebugEntry,
});

const {
renamePrompt,
openRenamePrompt,
handleRenamePromptChange,
handleRenamePromptCancel,
handleRenamePromptConfirm,
} = useRenameThreadPrompt({
threadsByWorkspace,
renameThread,
});

const handleRenameThread = useCallback(
(workspaceId: string, threadId: string) => {
openRenamePrompt(workspaceId, threadId);
},
[openRenamePrompt],
);

const {
activeImages,
attachImages,
Expand Down Expand Up @@ -1166,6 +1187,9 @@ function MainApp() {
});
removeImagesForThread(threadId);
},
onRenameThread: (workspaceId, threadId) => {
handleRenameThread(workspaceId, threadId);
},
onDeleteWorkspace: (workspaceId) => {
void removeWorkspace(workspaceId);
},
Expand Down Expand Up @@ -1463,6 +1487,15 @@ function MainApp() {
onPlanPanelResizeStart={onPlanPanelResizeStart}
/>
)}
{renamePrompt && (
<RenameThreadPrompt
currentName={renamePrompt.originalName}
name={renamePrompt.name}
onChange={handleRenamePromptChange}
onCancel={handleRenamePromptCancel}
onConfirm={handleRenamePromptConfirm}
/>
)}
{worktreePrompt && (
<WorktreePrompt
workspaceName={worktreePrompt.workspace.name}
Expand Down
3 changes: 3 additions & 0 deletions src/features/app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type SidebarProps = {
onToggleWorkspaceCollapse: (workspaceId: string, collapsed: boolean) => void;
onSelectThread: (workspaceId: string, threadId: string) => void;
onDeleteThread: (workspaceId: string, threadId: string) => void;
onRenameThread: (workspaceId: string, threadId: string) => void;
onDeleteWorkspace: (workspaceId: string) => void;
onDeleteWorktree: (workspaceId: string) => void;
onLoadOlderThreads: (workspaceId: string) => void;
Expand Down Expand Up @@ -86,6 +87,7 @@ export function Sidebar({
onToggleWorkspaceCollapse,
onSelectThread,
onDeleteThread,
onRenameThread,
onDeleteWorkspace,
onDeleteWorktree,
onLoadOlderThreads,
Expand Down Expand Up @@ -114,6 +116,7 @@ export function Sidebar({
const { showThreadMenu, showWorkspaceMenu, showWorktreeMenu } =
useSidebarMenus({
onDeleteThread,
onRenameThread,
onReloadWorkspaceThreads,
onDeleteWorkspace,
onDeleteWorktree,
Expand Down
10 changes: 8 additions & 2 deletions src/features/app/hooks/useSidebarMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { getCurrentWindow } from "@tauri-apps/api/window";

type SidebarMenuHandlers = {
onDeleteThread: (workspaceId: string, threadId: string) => void;
onRenameThread: (workspaceId: string, threadId: string) => void;
onReloadWorkspaceThreads: (workspaceId: string) => void;
onDeleteWorkspace: (workspaceId: string) => void;
onDeleteWorktree: (workspaceId: string) => void;
};

export function useSidebarMenus({
onDeleteThread,
onRenameThread,
onReloadWorkspaceThreads,
onDeleteWorkspace,
onDeleteWorktree,
Expand All @@ -20,6 +22,10 @@ export function useSidebarMenus({
async (event: MouseEvent, workspaceId: string, threadId: string) => {
event.preventDefault();
event.stopPropagation();
const renameItem = await MenuItem.new({
text: "Rename",
action: () => onRenameThread(workspaceId, threadId),
});
const archiveItem = await MenuItem.new({
text: "Archive",
action: () => onDeleteThread(workspaceId, threadId),
Expand All @@ -30,12 +36,12 @@ export function useSidebarMenus({
await navigator.clipboard.writeText(threadId);
},
});
const menu = await Menu.new({ items: [copyItem, archiveItem] });
const menu = await Menu.new({ items: [renameItem, copyItem, archiveItem] });
const window = getCurrentWindow();
const position = new LogicalPosition(event.clientX, event.clientY);
await menu.popup(position, window);
},
[onDeleteThread],
[onDeleteThread, onRenameThread],
);

const showWorkspaceMenu = useCallback(
Expand Down
2 changes: 2 additions & 0 deletions src/features/layout/hooks/useLayoutNodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type LayoutNodesOptions = {
onToggleWorkspaceCollapse: (workspaceId: string, collapsed: boolean) => void;
onSelectThread: (workspaceId: string, threadId: string) => void;
onDeleteThread: (workspaceId: string, threadId: string) => void;
onRenameThread: (workspaceId: string, threadId: string) => void;
onDeleteWorkspace: (workspaceId: string) => void;
onDeleteWorktree: (workspaceId: string) => void;
onLoadOlderThreads: (workspaceId: string) => void;
Expand Down Expand Up @@ -329,6 +330,7 @@ export function useLayoutNodes(options: LayoutNodesOptions): LayoutNodesResult {
onToggleWorkspaceCollapse={options.onToggleWorkspaceCollapse}
onSelectThread={options.onSelectThread}
onDeleteThread={options.onDeleteThread}
onRenameThread={options.onRenameThread}
onDeleteWorkspace={options.onDeleteWorkspace}
onDeleteWorktree={options.onDeleteWorktree}
onLoadOlderThreads={options.onLoadOlderThreads}
Expand Down
73 changes: 73 additions & 0 deletions src/features/threads/components/RenameThreadPrompt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { useEffect, useRef } from "react";

type RenameThreadPromptProps = {
currentName: string;
name: string;
onChange: (value: string) => void;
onCancel: () => void;
onConfirm: () => void;
};

export function RenameThreadPrompt({
currentName,
name,
onChange,
onCancel,
onConfirm,
}: RenameThreadPromptProps) {
const inputRef = useRef<HTMLInputElement | null>(null);

useEffect(() => {
inputRef.current?.focus();
inputRef.current?.select();
}, []);

return (
<div className="worktree-modal" role="dialog" aria-modal="true">
<div className="worktree-modal-backdrop" onClick={onCancel} />
<div className="worktree-modal-card">
<div className="worktree-modal-title">Rename thread</div>
<div className="worktree-modal-subtitle">
Current name: "{currentName}"
</div>
<label className="worktree-modal-label" htmlFor="thread-rename">
New name
</label>
<input
id="thread-rename"
ref={inputRef}
className="worktree-modal-input"
value={name}
onChange={(event) => onChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") {
event.preventDefault();
onCancel();
}
if (event.key === "Enter") {
event.preventDefault();
onConfirm();
}
}}
/>
<div className="worktree-modal-actions">
<button
className="ghost worktree-modal-button"
onClick={onCancel}
type="button"
>
Cancel
</button>
<button
className="primary worktree-modal-button"
onClick={onConfirm}
type="button"
disabled={name.trim().length === 0}
>
Rename
</button>
</div>
</div>
</div>
);
}
75 changes: 75 additions & 0 deletions src/features/threads/hooks/useRenameThreadPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useCallback, useState } from "react";
import type { ThreadSummary } from "../../../types";

type RenamePromptState = {
workspaceId: string;
threadId: string;
name: string;
originalName: string;
};

type UseRenameThreadPromptOptions = {
threadsByWorkspace: Record<string, ThreadSummary[]>;
renameThread: (workspaceId: string, threadId: string, name: string) => void;
};

export function useRenameThreadPrompt({
threadsByWorkspace,
renameThread,
}: UseRenameThreadPromptOptions) {
const [renamePrompt, setRenamePrompt] = useState<RenamePromptState | null>(
null,
);

const openRenamePrompt = useCallback(
(workspaceId: string, threadId: string) => {
const threads = threadsByWorkspace[workspaceId] ?? [];
const thread = threads.find((entry) => entry.id === threadId);
const currentName = thread?.name || "Thread";
setRenamePrompt({
workspaceId,
threadId,
name: currentName,
originalName: currentName,
});
},
[threadsByWorkspace],
);

const handleRenamePromptChange = useCallback((value: string) => {
setRenamePrompt((prev) =>
prev
? {
...prev,
name: value,
}
: prev,
);
}, []);

const handleRenamePromptCancel = useCallback(() => {
setRenamePrompt(null);
}, []);

const handleRenamePromptConfirm = useCallback(() => {
setRenamePrompt((prev) => {
if (!prev) {
return prev;
}
const trimmed = prev.name.trim();
if (!trimmed || trimmed === prev.originalName) {
return null;
}
renameThread(prev.workspaceId, prev.threadId, trimmed);
return null;
});
}, [renameThread]);

return {
renamePrompt,
openRenamePrompt,
handleRenamePromptChange,
handleRenamePromptCancel,
handleRenamePromptConfirm,
};
}
Loading