import { fetchLibraries, fetchBooks, getBookCoverUrl, LibraryDto, BookDto } from "../../../../lib/api"; import { BooksGrid, EmptyState } from "../../../components/BookCard"; import { LibrarySubPageHeader } from "../../../components/LibrarySubPageHeader"; import { CursorPagination } from "../../../components/ui"; import { notFound } from "next/navigation"; export const dynamic = "force-dynamic"; export default async function LibraryBooksPage({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ [key: string]: string | string[] | undefined }>; }) { const { id } = await params; const searchParamsAwaited = await searchParams; const cursor = typeof searchParamsAwaited.cursor === "string" ? searchParamsAwaited.cursor : undefined; const series = typeof searchParamsAwaited.series === "string" ? searchParamsAwaited.series : undefined; const limit = typeof searchParamsAwaited.limit === "string" ? parseInt(searchParamsAwaited.limit) : 20; const [library, booksPage] = await Promise.all([ fetchLibraries().then(libs => libs.find(l => l.id === id)), fetchBooks(id, series, cursor, limit).catch(() => ({ items: [] as BookDto[], next_cursor: null })) ]); if (!library) { notFound(); } const books = booksPage.items.map(book => ({ ...book, coverUrl: getBookCoverUrl(book.id) })); const nextCursor = booksPage.next_cursor; const seriesDisplayName = series === "unclassified" ? "Unclassified" : series; const hasNextPage = !!nextCursor; const hasPrevPage = !!cursor; return (