import Link from "next/link"; import type { Metadata } from "next"; import { requireUser } from "@/lib/auth"; import { getSettings } from "@/lib/settings"; import { getLibrary, getLibraryFacets, type LibraryFilters as Filters, type LibrarySort } from "@/lib/queries"; import { AppShell } from "@/components/AppShell"; import { LibraryCard } from "@/components/library/LibraryCard"; import { LibraryFilters } from "@/components/library/LibraryFilters"; import { SearchPendingProvider, SearchResults } from "@/components/SearchPending"; import type { EntryStatus, TitleType } from "@/generated/prisma/client"; export const metadata: Metadata = { title: "Bibliothek" }; const STATUSES = ["WATCHING", "PAUSED", "COMPLETED", "DROPPED", "WATCHLIST"]; const SORTS = ["aktualisiert", "hinzugefuegt", "titel", "bewertung", "jahr"]; export default async function LibraryPage({ searchParams, }: { searchParams: Promise>; }) { const user = await requireUser("/bibliothek"); const settings = await getSettings(); const params = await searchParams; const filters: Filters = { query: params.q?.trim() || undefined, status: STATUSES.includes(params.status ?? "") ? (params.status as EntryStatus) : undefined, type: params.typ === "SERIES" || params.typ === "MOVIE" ? (params.typ as TitleType) : undefined, genre: params.genre || undefined, tag: params.tag || undefined, provider: params.dienst || undefined, owned: params.sammlung === "1" ? true : undefined, sort: SORTS.includes(params.sortierung ?? "") ? (params.sortierung as LibrarySort) : undefined, }; const [items, facets] = await Promise.all([ getLibrary(user.id, filters), getLibraryFacets(user.id), ]); const hasFilters = Object.values(filters).some(Boolean); return (

Bibliothek

{facets.counts.ALLE === 0 ? "Noch nichts aufgenommen." : `${facets.counts.ALLE} ${facets.counts.ALLE === 1 ? "Titel" : "Titel"} — davon ${facets.counts.WATCHING} gerade am Laufen.`}

Titel hinzufügen
{facets.counts.ALLE > 0 && }
{items.length === 0 ? (

{facets.counts.ALLE === 0 ? "Deine Bibliothek ist noch leer." : hasFilters ? "Zu dieser Auswahl passt nichts." : "Hier ist nichts."}

{facets.counts.ALLE === 0 && ( Ersten Titel suchen )}
) : ( <>

{items.length} {items.length === 1 ? "Titel" : "Titel"}

    {items.map((item) => (
  • ))}
)}
); }