import Link from "next/link" import { ChevronLeft } from "lucide-react" import { prisma } from "@/lib/prisma" import { NovelCard } from "@/components/novel-card" import { notFound } from "next/navigation" export const dynamic = "force-dynamic" function collapseSeriesRows(rows: T[]): T[] { const pickedSeries = new Set() const output: T[] = [] for (const row of rows) { if (!row.seriesId) { output.push(row) continue } if (pickedSeries.has(row.seriesId)) continue pickedSeries.add(row.seriesId) output.push(row) } return output } export default async function GenreDetailPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params const genre = await prisma.genre.findUnique({ where: { slug } }) if (!genre) { notFound() } const allNovelsRaw = await prisma.novel.findMany({ where: { genres: { some: { genreId: genre.id } } }, select: { id: true, slug: true, title: true, authorName: true, coverColor: true, coverUrl: true, rating: true, views: true, totalChapters: true, status: true, seriesId: true, }, orderBy: { updatedAt: "desc" }, take: 80 }) const allNovels = collapseSeriesRows(allNovelsRaw).slice(0, 20) // Basic layout without sort for purely server side representation without search params. Optional searchParams can be added later if needed. return (
Thể Loại

{genre.name}

{genre.description}

{allNovels.length} truyện

{/* Spacer for symmetry if we add sort later */}
{allNovels.length === 0 ? (

Chưa có truyện nào

Thể loại này chưa có truyện, hãy quay lại sau.

) : (
{allNovels.map((novel) => ( ))}
)}
) }