"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 } 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 = () => { // TODO: Implement export functionality 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); setIsEditing(true); setTimeout(() => { inputRef.current?.focus(); inputRef.current?.select(); }, 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()); } 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 setNewName(e.target.value)} onBlur={handleNameSave} onKeyDown={handleInputKeyDown} /> ) : ( // Display project name as span, click to edit {activeProject?.name} )}
); const centerContent = (
{formatTimeCode( getTotalDuration(), "HH:MM:SS:FF", activeProject?.fps || 30 )}
); const rightContent = ( ); return ( ); }