"use client"; import { useRef, useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { clsx } from "clsx"; import { setTagsAction, updateEntryAction } from "@/app/actions/library"; import { useToasts } from "@/components/Toasts"; /** * Notizfeld, „wo schaue ich das" und eigene Tags. * * Gespeichert wird beim Verlassen des Feldes, nicht bei jedem Tastendruck — * das spart Anfragen und erspart das Suchen nach einem Speichern-Knopf. */ export function EntryNotes({ entryId, notes, whereToWatch, tags, suggestion, owned, ownedSource, }: { entryId: string; notes: string | null; whereToWatch: string | null; tags: string[]; /** Vorschlag aus der Streaming-Verfügbarkeit. */ suggestion: string | null; owned: boolean; ownedSource: string | null; }) { return (
); } /** * „Hab ich" — der Titel liegt in der eigenen Sammlung. * * Bewusst getrennt von „wo schaue ich das": Streaming-Verfügbarkeit kommt und * geht, der gekaufte Film auf dem Heimserver bleibt. Genau die Titel, die * nirgends mehr laufen, will man ja wiederfinden. */ function OwnedEditor({ entryId, owned, source, }: { entryId: string; owned: boolean; source: string | null; }) { const save = useAutosave(entryId); const [isOwned, setIsOwned] = useState(owned); const [text, setText] = useState(source ?? ""); const initial = useRef(source ?? ""); return (
{isOwned && (
setText(event.target.value)} onBlur={() => { if (text === initial.current) return; initial.current = text; save({ ownedSource: text }); }} list="fl-owned-quellen" placeholder="Jellyfin, Plex, NAS, Blu-ray …" className="fl-input py-1.5 text-sm" />
)}
); } function useAutosave(entryId: string) { const { report } = useToasts(); const router = useRouter(); const [, startTransition] = useTransition(); return (data: Record) => startTransition(async () => { const result = await updateEntryAction(entryId, data); if (!result.ok) report(result); router.refresh(); }); } function WhereToWatch({ entryId, value, suggestion, }: { entryId: string; value: string | null; suggestion: string | null; }) { const save = useAutosave(entryId); const [text, setText] = useState(value ?? ""); const initial = useRef(value ?? ""); return (
setText(event.target.value)} onBlur={() => { if (text === initial.current) return; initial.current = text; save({ whereToWatch: text }); }} placeholder={suggestion ? `Vorschlag: ${suggestion}` : "z. B. Netflix, Blu-ray, Mediathek"} className="fl-input" /> {suggestion && text !== suggestion && ( )}
); } function Notes({ entryId, value }: { entryId: string; value: string | null }) { const save = useAutosave(entryId); const [text, setText] = useState(value ?? ""); const initial = useRef(value ?? ""); return (