"use client"; import Link from "next/link"; import { Button } from "./ui/button"; import { ChevronLeft, Download } from "lucide-react"; import { useTimelineStore } from "@/stores/timeline-store"; import { HeaderBase } from "./header-base"; import { formatTimeCode } from "@/lib/time"; import { useProjectStore } from "@/stores/project-store"; import { KeyboardShortcutsHelp } from "./keyboard-shortcuts-help"; import { useState, useRef, useEffect } from "react"; import { Input } from "@/components/ui/input"; 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 = () => { // TODO: Implement export functionality console.log("Export project"); }; // When user clicks the project name, enter edit mode const handleNameClick = () => { if (!activeProject) return; setNewName(activeProject.name); setIsEditing(true); }; // Focus/select input when entering edit mode useEffect(() => { if (isEditing && inputRef.current) { inputRef.current.focus(); inputRef.current.select(); } }, [isEditing]); // 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()); } 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 using standard Input component setNewName(e.target.value)} onBlur={handleNameSave} onKeyDown={handleInputKeyDown} maxLength={64} aria-label="Project name" autoFocus /> ) : ( // Display project name as span, click to edit e.key === 'Enter' && handleNameClick()} >
{activeProject?.name}
)}
); const centerContent = (
{formatTimeCode( getTotalDuration(), "HH:MM:SS:FF", activeProject?.fps || 30 )}
); const rightContent = ( ); return ( ); }