From 68492df3028d2f5aa840b4b7b55930b5467b5a73 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 22 Jul 2025 12:43:27 +0200 Subject: [PATCH] Merge pull request [#422](https://github.com/mazeincoding/AppCut/issues/422) --- apps/web/src/components/editor-header.tsx | 63 ++++++++++++++++++- .../editor/properties-panel/index.tsx | 4 +- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/editor-header.tsx b/apps/web/src/components/editor-header.tsx index 3b51e182..7daf5270 100644 --- a/apps/web/src/components/editor-header.tsx +++ b/apps/web/src/components/editor-header.tsx @@ -8,16 +8,45 @@ 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"; +import { Input } from "@/components/ui/input"; 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 + // NOTE: This is already being worked on console.log("Export project"); }; + const handleNameClick = () => { + if (!activeProject) return; + setNewName(activeProject.name); + setIsEditing(true); + }; + + const handleNameSave = async () => { + if (activeProject && newName.trim() && newName !== activeProject.name) { + try { + await renameProject(activeProject.id, newName.trim()); + } catch (error) { + console.error("Failed to rename project:", error); + setNewName(activeProject.name); + } + } + 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} + onFocus={(e) => e.target.select()} + maxLength={64} + aria-label="Project name" + autoFocus + /> + ) : ( + e.key === "Enter" && handleNameClick()} + > +
+ {activeProject?.name} +
+
+ )} +
); @@ -62,7 +119,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" /> ); } diff --git a/apps/web/src/components/editor/properties-panel/index.tsx b/apps/web/src/components/editor/properties-panel/index.tsx index 9e28850f..4fc5d89d 100644 --- a/apps/web/src/components/editor/properties-panel/index.tsx +++ b/apps/web/src/components/editor/properties-panel/index.tsx @@ -103,7 +103,9 @@ function PropertyItem({ label, value }: { label: string; value: string }) { return (
- {value} + + {value} +
); }