import { fetchBooks, fetchAllSeries, BooksPageDto, SeriesPageDto, getBookCoverUrl } from "../../../lib/api"; import { getServerTranslations } from "../../../lib/i18n/server"; import { BooksGrid } from "../../components/BookCard"; import { OffsetPagination } from "../../components/ui"; import Image from "next/image"; import Link from "next/link"; export const dynamic = "force-dynamic"; export default async function AuthorDetailPage({ params, searchParams, }: { params: Promise<{ name: string }>; searchParams: Promise<{ [key: string]: string | string[] | undefined }>; }) { const { t } = await getServerTranslations(); const { name: encodedName } = await params; const authorName = decodeURIComponent(encodedName); const searchParamsAwaited = await searchParams; const page = typeof searchParamsAwaited.page === "string" ? parseInt(searchParamsAwaited.page) : 1; const limit = typeof searchParamsAwaited.limit === "string" ? parseInt(searchParamsAwaited.limit) : 20; // Fetch books by this author (server-side filtering via API) and series by this author const [booksPage, seriesPage] = await Promise.all([ fetchBooks(undefined, undefined, page, limit, undefined, undefined, authorName).catch( () => ({ items: [], total: 0, page: 1, limit }) as BooksPageDto ), fetchAllSeries(undefined, undefined, undefined, 1, 200, undefined, undefined, undefined, undefined, authorName).catch( () => ({ items: [], total: 0, page: 1, limit: 200 }) as SeriesPageDto ), ]); const totalPages = Math.ceil(booksPage.total / limit); const authorSeries = seriesPage.items; return ( <> {/* Breadcrumb */} {/* Author Header */}
{t("authors.bookCount", { count: String(s.book_count), plural: s.book_count !== 1 ? "s" : "" })}
{t("authors.noResults")}