From 283013c09d4855529e846951a1e090f0f16030a8 Mon Sep 17 00:00:00 2001
From: bndw <ben@bdw.to>
Date: Sat, 28 Feb 2026 19:34:02 -0800
Subject: feat: auto session naming

---
 renderer/src/components/Header.tsx | 81 +++++++++++++++++++++++++++++++-------
 1 file changed, 66 insertions(+), 15 deletions(-)

(limited to 'renderer/src/components/Header.tsx')

diff --git a/renderer/src/components/Header.tsx b/renderer/src/components/Header.tsx
index b4faa6e..a435519 100644
--- a/renderer/src/components/Header.tsx
+++ b/renderer/src/components/Header.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useState } from "react";
 import type { Project, Session, Phase } from "../types";
 
 type Theme = "dark" | "light";
@@ -14,6 +14,7 @@ interface HeaderProps {
   onCreateSession: () => void;
   onDeleteProject?: (id: string) => void;
   onDeleteSession?: (id: string) => void;
+  onRenameSession?: (id: string, name: string) => void;
   theme: Theme;
   onToggleTheme: () => void;
 }
@@ -37,6 +38,7 @@ export function Header({
   onCreateSession,
   onDeleteProject,
   onDeleteSession,
+  onRenameSession,
   theme,
   onToggleTheme,
 }: HeaderProps) {
@@ -54,6 +56,32 @@ export function Header({
     }
   };
 
+  const [isRenamingSession, setIsRenamingSession] = useState(false);
+  const [renameValue, setRenameValue] = useState("");
+  // Guard against double-commit (onKeyDown Enter → unmount → onBlur)
+  const renameCommitted = React.useRef(false);
+
+  const startRename = () => {
+    if (!selectedSession) return;
+    renameCommitted.current = false;
+    setRenameValue(selectedSession.name);
+    setIsRenamingSession(true);
+  };
+
+  const commitRename = () => {
+    if (renameCommitted.current) return;
+    renameCommitted.current = true;
+    if (selectedSession && onRenameSession && renameValue.trim()) {
+      onRenameSession(selectedSession.id, renameValue.trim());
+    }
+    setIsRenamingSession(false);
+  };
+
+  const cancelRename = () => {
+    renameCommitted.current = true; // prevent blur from committing after cancel
+    setIsRenamingSession(false);
+  };
+
   return (
     <header className="header">
       <div className="header-left">
@@ -88,21 +116,44 @@ export function Header({
 
         {selectedProject && (
           <>
-            <select
-              value={selectedSession?.id || ""}
-              onChange={(e) => {
-                const session = sessions.find((s) => s.id === e.target.value);
-                onSelectSession(session || null);
-              }}
-            >
-              <option value="">Select Session...</option>
-              {sessions.map((s) => (
-                <option key={s.id} value={s.id}>
-                  {s.name}
-                </option>
-              ))}
-            </select>
+            {isRenamingSession ? (
+              <input
+                autoFocus
+                value={renameValue}
+                onChange={(e) => setRenameValue(e.target.value)}
+                onKeyDown={(e) => {
+                  if (e.key === "Enter") commitRename();
+                  if (e.key === "Escape") cancelRename();
+                }}
+                onBlur={commitRename}
+                className="session-rename-input"
+              />
+            ) : (
+              <select
+                value={selectedSession?.id || ""}
+                onChange={(e) => {
+                  const session = sessions.find((s) => s.id === e.target.value);
+                  onSelectSession(session || null);
+                }}
+              >
+                <option value="">Select Session...</option>
+                {sessions.map((s) => (
+                  <option key={s.id} value={s.id}>
+                    {s.name}
+                  </option>
+                ))}
+              </select>
+            )}
             <button onClick={onCreateSession}>+ Session</button>
+            {selectedSession && onRenameSession && !isRenamingSession && (
+              <button
+                onClick={startRename}
+                className="btn-rename"
+                title="Rename session"
+              >
+                ✏️
+              </button>
+            )}
             {selectedSession && onDeleteSession && (
               <button
                 onClick={handleDeleteSession}
-- 
cgit v1.2.3

