Add moderation APIs and admin UI

Add moderator/admin backend APIs and client features for managing novels and chapters. New endpoints include mod chapter routes (paginated list, single GET, PUT, DELETE, and bulk optimize), mod novel routes (create, GET by id, update, delete), genre CRUD, user bookmarks, novel comments, and rating endpoints. Update EPUB import to use a shared slugify util. Enhance moderator UI: chapter manager gains pagination, bulk optimization preview/apply, edit/delete dialogs; novel client adds genre management and edit/delete flows. Also update Prisma schema, add a DB wipe script, remove unused lib/data.ts, and adjust related types/utils and bookmark context.
This commit is contained in:
2026-03-06 17:30:56 +07:00
parent ce805adb08
commit 75ed8e233b
31 changed files with 1853 additions and 687 deletions
+66 -3
View File
@@ -1,14 +1,37 @@
import Link from "next/link"
import { Eye } from "lucide-react"
import type { Chapter } from "@/lib/types"
import { formatViews } from "@/lib/data"
import { formatViews } from "@/lib/utils"
interface ChapterListProps {
chapters: Chapter[]
chapters: {
id: string
novelId: string
number: number
title: string
createdAt: string
views: number
}[]
novelSlug: string
currentPage: number
totalPages: number
totalChapters: number
}
export function ChapterList({ chapters, novelSlug }: ChapterListProps) {
const generatePagination = (currentPage: number, totalPages: number) => {
if (totalPages <= 7) {
return Array.from({ length: totalPages }, (_, i) => i + 1)
}
if (currentPage <= 3) {
return [1, 2, 3, 4, '...', totalPages]
}
if (currentPage >= totalPages - 2) {
return [1, '...', totalPages - 3, totalPages - 2, totalPages - 1, totalPages]
}
return [1, '...', currentPage - 1, currentPage, currentPage + 1, '...', totalPages]
}
export function ChapterList({ chapters, novelSlug, currentPage, totalPages, totalChapters }: ChapterListProps) {
return (
<div className="flex flex-col">
{chapters.map((chapter) => (
@@ -30,6 +53,46 @@ export function ChapterList({ chapters, novelSlug }: ChapterListProps) {
</div>
</Link>
))}
{totalPages > 1 && (
<div className="flex flex-col sm:flex-row items-center justify-between gap-4 border-t border-border p-4 bg-muted/10">
<div className="text-sm text-muted-foreground">
Trang <span className="font-medium text-foreground">{currentPage}</span> / {totalPages} (Tổng {totalChapters} chương)
</div>
<div className="flex items-center gap-1">
<Link
href={currentPage > 1 ? `/truyen/${novelSlug}?page=${currentPage - 1}` : '#'}
className={`inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md border border-input px-3 text-sm font-medium shadow-sm transition-colors ${currentPage <= 1 ? 'pointer-events-none opacity-50 bg-muted/50 text-muted-foreground' : 'bg-background hover:bg-accent hover:text-accent-foreground'}`}
aria-disabled={currentPage <= 1}
>
Trước
</Link>
{generatePagination(currentPage, totalPages).map((p, i) => (
<div key={i} className="hidden sm:block">
{p === '...' ? (
<span className="px-2 text-muted-foreground">...</span>
) : (
<Link
href={`/truyen/${novelSlug}?page=${p}`}
className={`inline-flex h-9 w-9 items-center justify-center whitespace-nowrap rounded-md border text-sm font-medium shadow-sm transition-colors ${currentPage === p ? 'bg-primary text-primary-foreground border-primary hover:bg-primary/90' : 'bg-background border-input hover:bg-accent hover:text-accent-foreground'}`}
>
{p}
</Link>
)}
</div>
))}
<Link
href={currentPage < totalPages ? `/truyen/${novelSlug}?page=${currentPage + 1}` : '#'}
className={`inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md border border-input px-3 text-sm font-medium shadow-sm transition-colors ${currentPage >= totalPages ? 'pointer-events-none opacity-50 bg-muted/50 text-muted-foreground' : 'bg-background hover:bg-accent hover:text-accent-foreground'}`}
aria-disabled={currentPage >= totalPages}
>
Sau
</Link>
</div>
</div>
)}
</div>
)
}