"use client"; import { useState } from "react"; import { Edit, X, Save } from "lucide-react"; import { api } from "@/lib/api"; import { toast } from "sonner"; import { GradientSpinner } from "./ui/GradientSpinner"; interface MetadataEditorProps { type: "artist" | "album" | "track"; id: string; currentData: { name?: string; title?: string; bio?: string; genres?: string[]; year?: number; mbid?: string; rgMbid?: string; coverUrl?: string; heroUrl?: string; }; onSave?: (updatedData: any) => void; } /** * Metadata Editor Component * Plex/Kavita-style metadata editor with pencil icon * Opens a modal for editing artist/album/track metadata */ export function MetadataEditor({ type, id, currentData, onSave, }: MetadataEditorProps) { const [isOpen, setIsOpen] = useState(false); const [isSaving, setIsSaving] = useState(false); const [formData, setFormData] = useState(currentData); const handleOpen = () => { setFormData(currentData); setIsOpen(true); }; const handleClose = () => { setIsOpen(false); setFormData(currentData); }; const handleSave = async () => { setIsSaving(true); try { // Call API to update metadata let response; if (type === "artist") { response = await api.updateArtistMetadata(id, formData); } else if (type === "album") { response = await api.updateAlbumMetadata(id, formData); } else { response = await api.updateTrackMetadata(id, formData); } toast.success( `${ type === "artist" ? "Artist" : type === "album" ? "Album" : "Track" } metadata updated` ); onSave?.(response); setIsOpen(false); } catch (error: any) { console.error("Failed to update metadata:", error); toast.error(error.message || "Failed to update metadata"); } finally { setIsSaving(false); } }; const handleChange = (field: string, value: any) => { setFormData((prev) => ({ ...prev, [field]: value })); }; return ( <> {/* Pencil Icon Button */} {/* Modal */} {isOpen && (
Note: Manually edited metadata will not be overwritten by automatic enrichment.