Skip to content
Open
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
20 changes: 15 additions & 5 deletions components/SessionSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1830,19 +1830,29 @@ function SessionItem({
const [deleting, setDeleting] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);

// Select the whole name once the rename input is mounted (startRename's
// immediate setTimeout can fire before the input exists).
useEffect(() => {
if (renaming) {
const id = requestAnimationFrame(() => inputRef.current?.select());
return () => cancelAnimationFrame(id);
}
}, [renaming]);

const title = session.name || session.firstMessage.slice(0, 50) || session.id.slice(0, 12);

const startRename = useCallback((e: React.MouseEvent) => {
e.stopPropagation();
setRenameValue(session.name ?? "");
setRenameValue(session.name || session.firstMessage.slice(0, 50) || session.id.slice(0, 12));
setRenaming(true);
setTimeout(() => inputRef.current?.select(), 0);
}, [session.name]);
}, [session.name, session.firstMessage, session.id]);

const commitRename = useCallback(async () => {
const name = renameValue.trim();
setRenaming(false);
if (name === (session.name ?? "")) return;
// No-op when unchanged: the fallback title (first message / id) isn't a
// real stored name, so don't persist it as one.
if (name === (session.name ?? "") || name === title) return;
try {
await fetch(`/api/sessions/${encodeURIComponent(session.id)}`, {
method: "PATCH",
Expand All @@ -1853,7 +1863,7 @@ function SessionItem({
} catch {
// ignore
}
}, [renameValue, session.id, session.name, onRenamed]);
}, [renameValue, session.id, session.name, onRenamed, title]);

const performDelete = useCallback(async () => {
setConfirmDelete(false);
Expand Down