2025-07-24 14:41:34 -07:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { Button } from "./ui/button";
|
2025-07-31 23:01:02 +02:00
|
|
|
import { ChevronDown, ArrowLeft, Download, SquarePen, Trash } from "lucide-react";
|
2025-07-24 14:41:34 -07:00
|
|
|
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";
|
2025-07-31 23:01:02 +02:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "./ui/dropdown-menu";
|
|
|
|
|
import Link from "next/link";
|
|
|
|
|
import { RenameProjectDialog } from "./rename-project-dialog";
|
|
|
|
|
import { DeleteProjectDialog } from "./delete-project-dialog";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2025-07-24 14:41:34 -07:00
|
|
|
|
|
|
|
|
export function EditorHeader() {
|
|
|
|
|
const { getTotalDuration } = useTimelineStore();
|
2025-07-31 23:01:02 +02:00
|
|
|
const { activeProject, renameProject, deleteProject } = useProjectStore();
|
|
|
|
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
|
|
|
|
const [isRenameDialogOpen, setIsRenameDialogOpen] = useState(false);
|
|
|
|
|
const router = useRouter();
|
2025-07-24 14:41:34 -07:00
|
|
|
|
|
|
|
|
const handleExport = () => {
|
|
|
|
|
// TODO: Implement export functionality
|
|
|
|
|
// NOTE: This is already being worked on
|
|
|
|
|
console.log("Export project");
|
2025-07-26 11:35:52 +02:00
|
|
|
window.open("https://youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
|
2025-07-24 14:41:34 -07:00
|
|
|
};
|
|
|
|
|
|
2025-07-31 23:01:02 +02:00
|
|
|
const handleNameSave = async (newName: string) => {
|
|
|
|
|
console.log("handleNameSave", newName);
|
2025-07-24 14:41:34 -07:00
|
|
|
if (activeProject && newName.trim() && newName !== activeProject.name) {
|
|
|
|
|
try {
|
|
|
|
|
await renameProject(activeProject.id, newName.trim());
|
2025-07-31 23:01:02 +02:00
|
|
|
setIsRenameDialogOpen(false);
|
2025-07-24 14:41:34 -07:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Failed to rename project:", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-31 23:01:02 +02:00
|
|
|
const handleDelete = () => {
|
|
|
|
|
if (activeProject) {
|
|
|
|
|
deleteProject(activeProject.id);
|
|
|
|
|
setIsDeleteDialogOpen(false);
|
|
|
|
|
router.push("/projects");
|
|
|
|
|
}
|
2025-07-24 14:41:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const leftContent = (
|
|
|
|
|
<div className="flex items-center gap-2">
|
2025-07-31 23:01:02 +02:00
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
className="h-auto py-1.5 px-2.5 flex items-center justify-center"
|
2025-07-24 14:41:34 -07:00
|
|
|
>
|
2025-07-31 23:01:02 +02:00
|
|
|
<ChevronDown className="text-muted-foreground" />
|
|
|
|
|
<span className="text-[0.85rem] mr-2">{activeProject?.name}</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="start" className="w-40">
|
|
|
|
|
<Link href="/projects">
|
|
|
|
|
<DropdownMenuItem className="flex items-center gap-1.5">
|
|
|
|
|
<ArrowLeft className="h-4 w-4" />
|
|
|
|
|
Projects
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</Link>
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
className="flex items-center gap-1.5"
|
|
|
|
|
onClick={() => setIsRenameDialogOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
<SquarePen className="h-4 w-4" />
|
|
|
|
|
Rename project
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
variant="destructive"
|
|
|
|
|
className="flex items-center gap-1.5"
|
|
|
|
|
onClick={() => setIsDeleteDialogOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
<Trash className="h-4 w-4" />
|
|
|
|
|
Delete Project
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
<RenameProjectDialog
|
|
|
|
|
isOpen={isRenameDialogOpen}
|
|
|
|
|
onOpenChange={setIsRenameDialogOpen}
|
|
|
|
|
onConfirm={handleNameSave}
|
|
|
|
|
projectName={activeProject?.name || ""}
|
|
|
|
|
/>
|
|
|
|
|
<DeleteProjectDialog
|
|
|
|
|
isOpen={isDeleteDialogOpen}
|
|
|
|
|
onOpenChange={setIsDeleteDialogOpen}
|
|
|
|
|
onConfirm={handleDelete}
|
|
|
|
|
projectName={activeProject?.name || ""}
|
|
|
|
|
/>
|
2025-07-24 14:41:34 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const centerContent = (
|
|
|
|
|
<div className="flex items-center gap-2 text-xs">
|
|
|
|
|
<span>
|
|
|
|
|
{formatTimeCode(
|
|
|
|
|
getTotalDuration(),
|
|
|
|
|
"HH:MM:SS:FF",
|
|
|
|
|
activeProject?.fps || 30
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const rightContent = (
|
|
|
|
|
<nav className="flex items-center gap-2">
|
|
|
|
|
<KeyboardShortcutsHelp />
|
|
|
|
|
<Button
|
|
|
|
|
size="sm"
|
2025-07-31 23:01:02 +02:00
|
|
|
className="h-7 text-xs !bg-linear-to-r from-cyan-400 to-blue-500 text-white hover:opacity-85 transition-opacity"
|
2025-07-24 14:41:34 -07:00
|
|
|
onClick={handleExport}
|
|
|
|
|
>
|
|
|
|
|
<Download className="h-4 w-4" />
|
|
|
|
|
<span className="text-sm">Export</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</nav>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<HeaderBase
|
|
|
|
|
leftContent={leftContent}
|
|
|
|
|
centerContent={centerContent}
|
|
|
|
|
rightContent={rightContent}
|
|
|
|
|
className="bg-background h-[3.2rem] px-4 items-center"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|