From 849fb3d2af29187abb4f21e724ff557614b90280 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 1 Jul 2025 16:06:36 +0200 Subject: [PATCH] refactor: editor header --- apps/web/src/components/editor-header.tsx | 7 +- .../components/editor/project-name-editor.tsx | 110 ------------------ 2 files changed, 4 insertions(+), 113 deletions(-) delete mode 100644 apps/web/src/components/editor/project-name-editor.tsx diff --git a/apps/web/src/components/editor-header.tsx b/apps/web/src/components/editor-header.tsx index aaea97b..e3d2359 100644 --- a/apps/web/src/components/editor-header.tsx +++ b/apps/web/src/components/editor-header.tsx @@ -5,11 +5,12 @@ import { Button } from "./ui/button"; import { ChevronLeft, Download } from "lucide-react"; import { useTimelineStore } from "@/stores/timeline-store"; import { HeaderBase } from "./header-base"; -import { ProjectNameEditor } from "./editor/project-name-editor"; import { formatTimeCode } from "@/lib/time"; +import { useProjectStore } from "@/stores/project-store"; export function EditorHeader() { const { getTotalDuration } = useTimelineStore(); + const { activeProject } = useProjectStore(); const handleExport = () => { // TODO: Implement export functionality @@ -19,12 +20,12 @@ export function EditorHeader() { const leftContent = (
+ {activeProject?.name} -
); diff --git a/apps/web/src/components/editor/project-name-editor.tsx b/apps/web/src/components/editor/project-name-editor.tsx deleted file mode 100644 index a4ff387..0000000 --- a/apps/web/src/components/editor/project-name-editor.tsx +++ /dev/null @@ -1,110 +0,0 @@ -"use client"; - -import { useState, useRef, useEffect } from "react"; -import { Input } from "../ui/input"; -import { useProjectStore } from "@/stores/project-store"; -import { Edit2, Check, X } from "lucide-react"; -import { Button } from "../ui/button"; - -interface ProjectNameEditorProps { - className?: string; -} - -export function ProjectNameEditor({ className }: ProjectNameEditorProps) { - const { activeProject, renameProject } = useProjectStore(); - const [isEditing, setIsEditing] = useState(false); - const [editValue, setEditValue] = useState(""); - const inputRef = useRef(null); - - useEffect(() => { - if (activeProject) { - setEditValue(activeProject.name); - } - }, [activeProject]); - - useEffect(() => { - if (isEditing && inputRef.current) { - inputRef.current.focus(); - inputRef.current.select(); - } - }, [isEditing]); - - const handleStartEdit = () => { - if (activeProject) { - setEditValue(activeProject.name); - setIsEditing(true); - } - }; - - const handleSave = () => { - if (editValue.trim() && activeProject) { - renameProject(activeProject.id, editValue.trim()); - setIsEditing(false); - } - }; - - const handleCancel = () => { - if (activeProject) { - setEditValue(activeProject.name); - } - setIsEditing(false); - }; - - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === "Enter") { - handleSave(); - } else if (e.key === "Escape") { - handleCancel(); - } - }; - - if (!activeProject) { - return Loading...; - } - - if (isEditing) { - return ( -
- setEditValue(e.target.value)} - onKeyDown={handleKeyDown} - className="h-7 text-sm px-3 py-1 min-w-[200px]" - size={1} - /> - - -
- ); - } - - return ( -
- {activeProject.name} - -
- ); -} \ No newline at end of file