diff --git a/apps/web/src/components/editor-header.tsx b/apps/web/src/components/editor-header.tsx index cf86df81..e9bad2e1 100644 --- a/apps/web/src/components/editor-header.tsx +++ b/apps/web/src/components/editor-header.tsx @@ -13,8 +13,10 @@ import { useState, useRef } from "react"; export function EditorHeader() { const { getTotalDuration } = useTimelineStore(); const { activeProject, renameProject } = useProjectStore(); + // State for edit mode and project name input const [isEditing, setIsEditing] = useState(false); const [newName, setNewName] = useState(activeProject?.name || ""); + // Ref for focusing/selecting the input const inputRef = useRef(null); const handleExport = () => { @@ -22,6 +24,7 @@ export function EditorHeader() { console.log("Export project"); }; + // When user clicks the project name, enter edit mode and select all text const handleNameClick = () => { if (!activeProject) return; setNewName(activeProject.name); @@ -32,6 +35,7 @@ export function EditorHeader() { }, 0); }; + // Save the new name if changed, exit edit mode const handleNameSave = async () => { if (activeProject && newName.trim() && newName !== activeProject.name) { await renameProject(activeProject.id, newName.trim()); @@ -39,11 +43,13 @@ export function EditorHeader() { setIsEditing(false); }; + // Handle Enter (save) and Escape (cancel) in the input const handleInputKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") handleNameSave(); else if (e.key === "Escape") setIsEditing(false); }; + // Project name in header: editable input or span const leftContent = (
{isEditing ? ( + // Editable input for project name ) : ( + // Display project name as span, click to edit