"use client"; import { Button } from "../ui/button"; import { useRef, useState } from "react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "../ui/dropdown-menu"; import Link from "next/link"; import { RenameProjectDialog } from "./dialogs/rename-project-dialog"; import { DeleteProjectDialog } from "./dialogs/delete-project-dialog"; import { useRouter } from "next/navigation"; import { FaDiscord } from "react-icons/fa6"; import { ExportButton } from "./export-button"; import { ThemeToggle } from "../theme-toggle"; import { DEFAULT_LOGO_URL, SOCIAL_LINKS } from "@/constants/site-constants"; import { toast } from "sonner"; import { useEditor } from "@/hooks/use-editor"; import { ArrowLeft02Icon, CommandIcon } from "@hugeicons/core-free-icons"; import { HugeiconsIcon } from "@hugeicons/react"; import { ShortcutsDialog } from "./dialogs/shortcuts-dialog"; import Image from "next/image"; import { cn } from "@/utils/ui"; export function EditorHeader() { return (
); } function ProjectDropdown() { const [openDialog, setOpenDialog] = useState< "delete" | "rename" | "shortcuts" | null >(null); const [isExiting, setIsExiting] = useState(false); const router = useRouter(); const editor = useEditor(); const activeProject = editor.project.getActive(); const handleExit = async () => { if (isExiting) return; setIsExiting(true); try { await editor.project.prepareExit(); editor.project.closeProject(); } catch (error) { console.error("Failed to prepare project exit:", error); } finally { editor.project.closeProject(); router.push("/projects"); } }; const handleSaveProjectName = async (newName: string) => { if ( activeProject && newName.trim() && newName !== activeProject.metadata.name ) { try { await editor.project.renameProject({ id: activeProject.metadata.id, name: newName.trim(), }); } catch (error) { toast.error("Failed to rename project", { description: error instanceof Error ? error.message : "Please try again", }); } finally { setOpenDialog(null); } } }; const handleDeleteProject = async () => { if (activeProject) { try { await editor.project.deleteProjects({ ids: [activeProject.metadata.id], }); router.push("/projects"); } catch (error) { toast.error("Failed to delete project", { description: error instanceof Error ? error.message : "Please try again", }); } finally { setOpenDialog(null); } } }; return ( <> Exit project setOpenDialog("shortcuts")} > Keyboard shortcuts Discord setOpenDialog(isOpen ? "rename" : null)} onConfirm={(newName) => handleSaveProjectName(newName)} projectName={activeProject?.metadata.name || ""} /> setOpenDialog(isOpen ? "delete" : null)} onConfirm={handleDeleteProject} projectNames={[activeProject?.metadata.name || ""]} /> setOpenDialog(isOpen ? "shortcuts" : null)} /> ); } function EditableProjectName() { const editor = useEditor(); const activeProject = editor.project.getActive(); const [isEditing, setIsEditing] = useState(false); const inputRef = useRef(null); const originalNameRef = useRef(""); const projectName = activeProject?.metadata.name || ""; const startEditing = () => { if (isEditing) return; originalNameRef.current = projectName; setIsEditing(true); requestAnimationFrame(() => { inputRef.current?.select(); }); }; const saveEdit = async () => { if (!inputRef.current || !activeProject) return; const newName = inputRef.current.value.trim(); setIsEditing(false); if (!newName) { inputRef.current.value = originalNameRef.current; return; } if (newName !== originalNameRef.current) { try { await editor.project.renameProject({ id: activeProject.metadata.id, name: newName, }); } catch (error) { toast.error("Failed to rename project", { description: error instanceof Error ? error.message : "Please try again", }); } } }; const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault(); inputRef.current?.blur(); } else if (event.key === "Escape") { event.preventDefault(); if (inputRef.current) { inputRef.current.value = originalNameRef.current; } setIsEditing(false); inputRef.current?.blur(); } }; return ( ); }