From b6a8ca79f6ca184bcb4923814ba80b0c9436de87 Mon Sep 17 00:00:00 2001 From: ayush18pop Date: Tue, 22 Jul 2025 13:15:39 +0530 Subject: [PATCH] feat: add project renaming functionality in editor header --- apps/web/src/components/editor-header.tsx | 51 +++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/editor-header.tsx b/apps/web/src/components/editor-header.tsx index 3b51e182..cf86df81 100644 --- a/apps/web/src/components/editor-header.tsx +++ b/apps/web/src/components/editor-header.tsx @@ -8,16 +8,42 @@ 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 } = useProjectStore(); + const { activeProject, renameProject } = useProjectStore(); + const [isEditing, setIsEditing] = useState(false); + const [newName, setNewName] = useState(activeProject?.name || ""); + const inputRef = useRef(null); const handleExport = () => { // TODO: Implement export functionality console.log("Export project"); }; + const handleNameClick = () => { + if (!activeProject) return; + setNewName(activeProject.name); + setIsEditing(true); + setTimeout(() => { + inputRef.current?.focus(); + inputRef.current?.select(); + }, 0); + }; + + const handleNameSave = async () => { + if (activeProject && newName.trim() && newName !== activeProject.name) { + await renameProject(activeProject.id, newName.trim()); + } + setIsEditing(false); + }; + + const handleInputKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter") handleNameSave(); + else if (e.key === "Escape") setIsEditing(false); + }; + const leftContent = (
- {activeProject?.name} +
+ {isEditing ? ( + setNewName(e.target.value)} + onBlur={handleNameSave} + onKeyDown={handleInputKeyDown} + /> + ) : ( + + {activeProject?.name} + + )} +
); @@ -62,7 +107,7 @@ export function EditorHeader() { leftContent={leftContent} centerContent={centerContent} rightContent={rightContent} - className="bg-background h-[3.2rem] px-4" + className="bg-background h-[3.2rem] px-4 items-center" /> ); }