refactor: Remove series-related fields and components to streamline novel management
Build and Push Reader Image / docker (push) Successful in 41s

- Eliminated seriesId and related fields from various models and components to simplify the data structure.
- Updated UI components to reflect the removal of series dependencies, enhancing clarity and maintainability.
- Adjusted API calls and data handling to ensure compatibility with the new structure.
This commit is contained in:
2026-05-12 14:37:37 +07:00
parent 09734cdadd
commit 3036854cf2
14 changed files with 48 additions and 687 deletions
+5 -3
View File
@@ -186,6 +186,7 @@ export function ImportBatchClient() {
formParse.append("preview", "true")
formParse.append("splitMode", splitMode)
if (splitMode === "regex") formParse.append("chapterRegex", chapterStartPattern)
formParse.append("enforceMaxChapters", "true")
const r3 = await fetch("/api/mod/epub", { method: "POST", credentials: "include", body: formParse, signal })
const d3 = await r3.json().catch(() => ({}))
@@ -199,7 +200,7 @@ export function ImportBatchClient() {
}
const chapterCount = Number(d3?.novel?.totalChapters ?? d3?.chapterCount ?? 0)
if (d3?.importBlocked === true || chapterCount > BATCH_IMPORT_MAX_CHAPTERS) {
if (d3?.importBlocked === true) {
return {
fileName: displayPath,
ok: false,
@@ -234,6 +235,7 @@ export function ImportBatchClient() {
formImport.append("description", description)
formImport.append("genreIds", genreIds.join(","))
formImport.append("replaceExisting", String(replaceExisting))
formImport.append("enforceMaxChapters", "true")
const r4 = await fetch("/api/mod/epub", { method: "POST", credentials: "include", body: formImport, signal })
const d4 = await r4.json().catch(() => ({}))
@@ -367,8 +369,8 @@ export function ImportBatchClient() {
Ghi đè nếu trùng tiêu đ (tắt = batch chỉ skip khi đã truyện cùng tiêu đ)
</label>
<p className="text-xs text-muted-foreground">
An toàn batch: tối đa {BATCH_IMPORT_MAX_CHAPTERS.toLocaleString()} chương sau khi tách mỗi file; quá{" "}
{Math.round(BATCH_IMPORT_MAX_MS_PER_FILE / 60000)} phút/file thì bỏ qua xử file tiếp theo.
An toàn batch (chỉ khi import nhiều): tối đa {BATCH_IMPORT_MAX_CHAPTERS.toLocaleString()} chương sau khi tách mỗi file; quá{" "}
{Math.round(BATCH_IMPORT_MAX_MS_PER_FILE / 60000)} phút/file thì bỏ qua xử file tiếp theo. Import một EPUB trên trang khác không bị giới hạn này.
</p>
</section>
+1 -7
View File
@@ -11,7 +11,6 @@ export default async function ModDashboardPage() {
let novelCount = 0
let totalViews = 0
let commentCount = 0
let seriesCount = 0
try {
const accessToken = (await cookies()).get(AUTH_COOKIE_NAME)?.value || ""
@@ -24,7 +23,6 @@ export default async function ModDashboardPage() {
novelCount = Number(data?.novelCount || 0)
totalViews = Number(data?.totalViews || 0)
commentCount = Number(data?.commentCount || 0)
seriesCount = Number(data?.seriesCount || 0)
}
} catch (error) {
console.error("Failed to fetch mod overview", error)
@@ -37,7 +35,7 @@ export default async function ModDashboardPage() {
Chào mừng bạn đến với trang quản trị dành cho Moderator.
</p>
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="rounded-xl border bg-card text-card-foreground shadow p-6">
<h3 className="font-semibold text-lg">Tổng truyện</h3>
<p className="text-3xl font-bold mt-2">{novelCount}</p>
@@ -50,10 +48,6 @@ export default async function ModDashboardPage() {
<h3 className="font-semibold text-lg">Bình luận mới</h3>
<p className="text-3xl font-bold mt-2">{commentCount}</p>
</div>
<div className="rounded-xl border bg-card text-card-foreground shadow p-6">
<h3 className="font-semibold text-lg">Tổng series</h3>
<p className="text-3xl font-bold mt-2">{seriesCount}</p>
</div>
</div>
</div>
)
-8
View File
@@ -1,8 +0,0 @@
import { requireModSessionUser } from "@/lib/server-auth"
import { SeriesClient } from "./series-client"
export default async function ModSeriesPage() {
await requireModSessionUser()
return <SeriesClient />
}
-230
View File
@@ -1,230 +0,0 @@
"use client"
import { useEffect, useMemo, useState } from "react"
import { Layers, Loader2, Pencil, Plus, Save, Trash2, X } from "lucide-react"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
interface SeriesItem {
id: string
name: string
slug: string
description?: string | null
_count?: {
novels: number
}
}
export function SeriesClient() {
const [series, setSeries] = useState<SeriesItem[]>([])
const [loading, setLoading] = useState(true)
const [submitting, setSubmitting] = useState(false)
const [name, setName] = useState("")
const [description, setDescription] = useState("")
const [editingId, setEditingId] = useState<string | null>(null)
const [keyword, setKeyword] = useState("")
const filteredSeries = useMemo(() => {
const q = keyword.trim().toLowerCase()
if (!q) return series
return series.filter((item) => {
return (
item.name.toLowerCase().includes(q) ||
item.slug.toLowerCase().includes(q) ||
(item.description || "").toLowerCase().includes(q)
)
})
}, [keyword, series])
const fetchSeries = async () => {
try {
const res = await fetch("/api/mod/series")
if (!res.ok) throw new Error("Không thể tải danh sách series")
const data = await res.json()
setSeries(data)
} catch (error: any) {
toast.error(error.message || "Không thể tải danh sách series")
} finally {
setLoading(false)
}
}
useEffect(() => {
fetchSeries()
}, [])
const resetForm = () => {
setEditingId(null)
setName("")
setDescription("")
}
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
if (!name.trim()) {
toast.error("Vui lòng nhập tên series")
return
}
setSubmitting(true)
try {
const payload = {
id: editingId,
name: name.trim(),
description: description.trim(),
}
const res = await fetch("/api/mod/series", {
method: editingId ? "PUT" : "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
})
const data = await res.json()
if (!res.ok) {
throw new Error(data.error || "Không thể lưu series")
}
toast.success(editingId ? "Đã cập nhật series" : "Đã tạo series")
resetForm()
fetchSeries()
} catch (error: any) {
toast.error(error.message || "Không thể lưu series")
} finally {
setSubmitting(false)
}
}
const handleEdit = (item: SeriesItem) => {
setEditingId(item.id)
setName(item.name)
setDescription(item.description || "")
}
const handleDelete = async (id: string) => {
if (!confirm("Bạn chắc chắn muốn xóa series này?")) return
setSubmitting(true)
try {
const res = await fetch(`/api/mod/series?id=${id}`, { method: "DELETE" })
const data = await res.json()
if (!res.ok) {
throw new Error(data.error || "Không thể xóa series")
}
toast.success("Đã xóa series")
if (editingId === id) resetForm()
fetchSeries()
} catch (error: any) {
toast.error(error.message || "Không thể xóa series")
} finally {
setSubmitting(false)
}
}
return (
<div className="space-y-6">
<div className="bg-card rounded-xl border shadow-sm p-4 flex items-center justify-between">
<h1 className="text-2xl font-bold flex items-center gap-2">
<Layers className="h-6 w-6 text-primary" /> Quản series
</h1>
<Input
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
placeholder="Tìm series..."
className="max-w-xs"
/>
</div>
<div className="grid grid-cols-1 xl:grid-cols-3 gap-4">
<div className="xl:col-span-1 rounded-xl border bg-card p-4 shadow-sm">
<h2 className="text-base font-semibold mb-3">{editingId ? "Chỉnh sửa series" : "Tạo series mới"}</h2>
<form onSubmit={handleSubmit} className="space-y-3">
<div className="space-y-2">
<label className="text-sm font-medium">Tên series</label>
<Input value={name} onChange={(e) => setName(e.target.value)} placeholder="Ví dụ: Overlord" />
</div>
<div className="space-y-2">
<label className="text-sm font-medium"> tả</label>
<Textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Mô tả ngắn về series"
rows={4}
/>
</div>
<div className="flex gap-2">
<Button type="submit" disabled={submitting} className="gap-2">
{submitting && <Loader2 className="h-4 w-4 animate-spin" />}
{editingId ? <Save className="h-4 w-4" /> : <Plus className="h-4 w-4" />}
{editingId ? "Lưu" : "Tạo"}
</Button>
{editingId && (
<Button type="button" variant="outline" onClick={resetForm} className="gap-2">
<X className="h-4 w-4" /> Hủy
</Button>
)}
</div>
</form>
</div>
<div className="xl:col-span-2 rounded-xl border bg-card shadow-sm overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-sm text-left">
<thead className="text-xs uppercase bg-muted/50 text-muted-foreground border-b border-border">
<tr>
<th className="px-4 py-3 font-semibold">Tên</th>
<th className="px-4 py-3 font-semibold">Slug</th>
<th className="px-4 py-3 font-semibold">Số truyện</th>
<th className="px-4 py-3 font-semibold"> tả</th>
<th className="px-4 py-3 text-right font-semibold">Thao tác</th>
</tr>
</thead>
<tbody>
{loading ? (
<tr>
<td colSpan={5} className="p-8 text-center text-muted-foreground">
<Loader2 className="w-5 h-5 animate-spin mx-auto" />
</td>
</tr>
) : filteredSeries.length === 0 ? (
<tr>
<td colSpan={5} className="p-8 text-center text-muted-foreground">
Chưa series nào
</td>
</tr>
) : (
filteredSeries.map((item) => (
<tr key={item.id} className="border-b border-border last:border-0 hover:bg-muted/30">
<td className="px-4 py-3 font-medium">{item.name}</td>
<td className="px-4 py-3 text-muted-foreground">{item.slug}</td>
<td className="px-4 py-3">{item._count?.novels ?? 0}</td>
<td className="px-4 py-3 text-muted-foreground max-w-sm truncate">{item.description || "-"}</td>
<td className="px-4 py-3">
<div className="flex items-center justify-end gap-2">
<Button size="icon" variant="outline" className="h-8 w-8" onClick={() => handleEdit(item)}>
<Pencil className="h-4 w-4" />
</Button>
<Button
size="icon"
variant="outline"
className="h-8 w-8 text-red-600 border-red-200 hover:bg-red-50"
onClick={() => handleDelete(item.id)}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</td>
</tr>
))
)}
</tbody>
</table>
</div>
</div>
</div>
</div>
)
}
@@ -24,11 +24,6 @@ type MissingNovel = {
description: string
totalChapters: number
updatedAt: string
series: {
id: string
name: string
slug: string
} | null
genres: Genre[]
missing: Record<MissingKey, boolean>
}
@@ -528,7 +523,7 @@ export function MissingFieldsClient() {
<Input
value={queryInput}
onChange={(e) => setQueryInput(e.target.value)}
placeholder="Tìm theo tên truyện, slug, tác giả, series..."
placeholder="Tìm theo tên truyện, slug, tác giả..."
onKeyDown={(e) => {
if (e.key === "Enter") {
setSearchKeyword(queryInput)
@@ -658,7 +653,7 @@ export function MissingFieldsClient() {
<Link href={`/truyen/${item.slug}`} className="font-semibold text-primary hover:underline" target="_blank">
{item.title}
</Link>
<p className="text-xs text-muted-foreground">{item.series?.name || "Độc lập"} - {item.totalChapters} chương</p>
<p className="text-xs text-muted-foreground">{item.totalChapters} chương</p>
<div className="flex flex-wrap gap-1">
{allMissingKeys.filter((key) => item.missing[key]).map((key) => (
<span key={key} className="rounded-full border border-amber-300 bg-amber-100 px-2 py-0.5 text-[11px] font-medium text-amber-700">
+8 -291
View File
@@ -28,11 +28,6 @@ interface Novel {
status: string
totalChapters: number
coverUrl?: string
series?: {
id: string
name: string
slug: string
} | null
}
interface Genre {
@@ -40,15 +35,6 @@ interface Genre {
name: string
}
interface SeriesOption {
id: string
name: string
slug: string
_count?: {
novels: number
}
}
interface EpubPreviewData {
fileName: string
splitMode: "toc" | "regex"
@@ -139,9 +125,6 @@ export function NovelClient() {
const [epubTitle, setEpubTitle] = useState("")
const [epubAuthorName, setEpubAuthorName] = useState("")
const [epubDescription, setEpubDescription] = useState("")
const [epubSeriesMode, setEpubSeriesMode] = useState<"none" | "existing" | "new">("none")
const [epubSeriesId, setEpubSeriesId] = useState("")
const [epubSeriesName, setEpubSeriesName] = useState("")
const [epubSplitMode, setEpubSplitMode] = useState<"toc" | "regex">("toc")
const [epubRegexPreset, setEpubRegexPreset] = useState<string>("vi_chuong_hoi")
const [epubCustomRegex, setEpubCustomRegex] = useState("")
@@ -155,9 +138,6 @@ export function NovelClient() {
const [originalAuthorName, setOriginalAuthorName] = useState("")
const [description, setDescription] = useState("")
const [coverUrl, setCoverUrl] = useState("")
const [seriesMode, setSeriesMode] = useState<"none" | "existing" | "new">("none")
const [selectedSeriesId, setSelectedSeriesId] = useState("")
const [newSeriesName, setNewSeriesName] = useState("")
const [status, setStatus] = useState("Đang ra")
// View state
@@ -171,7 +151,6 @@ export function NovelClient() {
// Genre states
const [genres, setGenres] = useState<Genre[]>([])
const [seriesList, setSeriesList] = useState<SeriesOption[]>([])
const [selectedGenres, setSelectedGenres] = useState<string[]>([])
const [genreQuery, setGenreQuery] = useState("")
const [addingGenre, setAddingGenre] = useState(false)
@@ -340,14 +319,9 @@ export function NovelClient() {
}
}
const fetchSeries = async () => {
setSeriesList([])
}
useEffect(() => {
fetchNovels()
fetchGenres()
fetchSeries()
}, [])
const normalizeGenreName = (value: string) => value.trim().toLowerCase()
@@ -359,9 +333,6 @@ export function NovelClient() {
setOriginalAuthorName("")
setDescription("")
setCoverUrl("")
setSeriesMode("none")
setSelectedSeriesId("")
setNewSeriesName("")
setStatus("Đang ra")
setSelectedGenres([])
setGenreQuery("")
@@ -377,9 +348,6 @@ export function NovelClient() {
setOriginalAuthorName((prefill.originalAuthorName || nextAuthor).trim())
setDescription((prefill.description || "").trim())
setCoverUrl((prefill.coverUrl || "").trim())
setSeriesMode("none")
setSelectedSeriesId("")
setNewSeriesName("")
setGenreQuery("")
const validStatus = ["Đang ra", "Hoàn thành", "Tạm ngưng"].includes(prefill.status || "")
@@ -448,7 +416,7 @@ export function NovelClient() {
if (!keyword) return novels
return novels.filter((novel) => {
const searchable = [novel.title, novel.authorName, novel.series?.name || ""].join(" ").toLowerCase()
const searchable = [novel.title, novel.authorName].join(" ").toLowerCase()
return searchable.includes(keyword)
})
}, [novels, searchKeyword])
@@ -546,7 +514,6 @@ export function NovelClient() {
toast.success(`Đã xóa ${data.deletedCount || selectedNovelIds.length} truyện`)
setSelectedNovelIds([])
fetchNovels()
fetchSeries()
} catch (error: any) {
toast.error(error.message || "Lỗi khi xóa hàng loạt")
} finally {
@@ -720,20 +687,6 @@ export function NovelClient() {
return
}
const resolvedNewSeriesName = seriesMode === "new"
? (newSeriesName.trim() || title.trim())
: ""
if (seriesMode === "existing" && !selectedSeriesId) {
toast.error("Vui lòng chọn series đã có")
return
}
if (seriesMode === "new" && !resolvedNewSeriesName) {
toast.error("Vui lòng nhập tên series mới")
return
}
setSubmitting(true)
try {
const res = await fetch("/api/mod/truyen", {
@@ -747,8 +700,6 @@ export function NovelClient() {
description,
coverUrl,
genreIds: selectedGenres,
seriesId: seriesMode === "existing" ? selectedSeriesId : undefined,
seriesName: seriesMode === "new" ? resolvedNewSeriesName : undefined,
}),
})
if (!res.ok) throw new Error("Thêm mới thất bại")
@@ -756,7 +707,6 @@ export function NovelClient() {
setOpenAdd(false)
resetAddForm()
fetchNovels()
fetchSeries()
} catch {
toast.error("Lỗi khi thêm truyện mới")
} finally {
@@ -775,9 +725,6 @@ export function NovelClient() {
setEpubTitle("")
setEpubAuthorName("")
setEpubDescription("")
setEpubSeriesMode("none")
setEpubSeriesId("")
setEpubSeriesName("")
setEpubSplitMode("toc")
setEpubRegexPreset("vi_chuong_hoi")
setEpubCustomRegex("")
@@ -811,9 +758,6 @@ export function NovelClient() {
const formData = new FormData()
formData.append("file", file)
formData.append("preview", "true")
formData.append("seriesMode", epubSeriesMode)
if (epubSeriesMode === "existing") formData.append("seriesId", epubSeriesId)
if (epubSeriesMode === "new") formData.append("seriesName", epubSeriesName)
formData.append("splitMode", splitMode)
if (splitMode === "regex") {
@@ -930,25 +874,12 @@ export function NovelClient() {
return
}
if (epubSeriesMode === "existing" && !epubSeriesId) {
toast.error("Vui lòng chọn series đã có")
return
}
if (epubSeriesMode === "new" && !epubSeriesName.trim()) {
toast.error("Vui lòng nhập tên series mới")
return
}
setUploadingEpub(true)
const formData = new FormData()
formData.append("file", pendingEpubFile)
formData.append("title", epubTitle)
formData.append("authorName", epubAuthorName)
formData.append("description", epubDescription)
formData.append("seriesMode", epubSeriesMode)
if (epubSeriesMode === "existing") formData.append("seriesId", epubSeriesId)
if (epubSeriesMode === "new") formData.append("seriesName", epubSeriesName.trim())
formData.append("splitMode", epubSplitMode)
if (epubSplitMode === "regex") {
@@ -988,7 +919,6 @@ export function NovelClient() {
}
resetEpubPreviewState()
fetchNovels()
fetchSeries()
} catch (err: any) {
toast.error(err.message || "Có lỗi xảy ra khi xuất bản truyện")
} finally {
@@ -1002,16 +932,6 @@ export function NovelClient() {
return
}
if (epubSeriesMode === "existing" && !epubSeriesId) {
toast.error("Vui lòng chọn series đã có")
return
}
if (epubSeriesMode === "new" && !epubSeriesName.trim()) {
toast.error("Vui lòng nhập tên series mới")
return
}
setUploadingEpub(true)
initializeBulkProgress(pendingEpubFiles)
@@ -1026,9 +946,6 @@ export function NovelClient() {
try {
const formData = new FormData()
formData.append("file", file)
formData.append("seriesMode", epubSeriesMode)
if (epubSeriesMode === "existing") formData.append("seriesId", epubSeriesId)
if (epubSeriesMode === "new") formData.append("seriesName", epubSeriesName.trim())
formData.append("splitMode", "toc")
setBulkProgressItem(fileKey, {
@@ -1119,7 +1036,6 @@ export function NovelClient() {
resetEpubPreviewState()
fetchNovels()
fetchSeries()
} finally {
setUploadingEpub(false)
}
@@ -1161,15 +1077,6 @@ export function NovelClient() {
setEditingNovel(novel)
setTitle(novel.title)
setAuthorName(novel.authorName)
if (novel.series?.id) {
setSeriesMode("existing")
setSelectedSeriesId(novel.series.id)
setNewSeriesName("")
} else {
setSeriesMode("none")
setSelectedSeriesId("")
setNewSeriesName("")
}
setStatus(novel.status)
setDescription("")
setGenreQuery("")
@@ -1186,11 +1093,6 @@ export function NovelClient() {
setDescription(data.description || "")
setOriginalTitle(data.originalTitle || "")
setOriginalAuthorName(data.originalAuthorName || "")
if (data.series?.id) {
setSeriesMode("existing")
setSelectedSeriesId(data.series.id)
setNewSeriesName("")
}
if (data.genres && Array.isArray(data.genres)) {
setSelectedGenres(data.genres.map((g: any) => g.id))
} else {
@@ -1213,16 +1115,6 @@ export function NovelClient() {
return
}
if (seriesMode === "existing" && !selectedSeriesId) {
toast.error("Vui lòng chọn series đã có")
return
}
if (seriesMode === "new" && !newSeriesName.trim()) {
toast.error("Vui lòng nhập tên series mới")
return
}
setSubmitting(true)
try {
const res = await fetch("/api/mod/truyen", {
@@ -1247,7 +1139,6 @@ export function NovelClient() {
toast.success("Cập nhật truyện thành công!")
setOpenEdit(false)
fetchNovels()
fetchSeries()
} catch (error: any) {
toast.error(error.message)
} finally {
@@ -1501,53 +1392,6 @@ export function NovelClient() {
<label className="text-xs font-medium text-muted-foreground"> tả</label>
<Textarea value={epubDescription} onChange={(e) => setEpubDescription(e.target.value)} rows={3} />
</div>
<div className="grid gap-2">
<label className="text-xs font-medium text-muted-foreground">Series (tùy chọn)</label>
<select
value={epubSeriesMode}
onChange={(e) => {
const mode = e.target.value as "none" | "existing" | "new"
setEpubSeriesMode(mode)
if (mode !== "existing") setEpubSeriesId("")
if (mode === "new" && !epubSeriesName.trim()) {
setEpubSeriesName(epubTitle.trim())
}
if (mode !== "new") setEpubSeriesName("")
}}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="none">Không gán series</option>
<option value="existing">Thêm vào series sẵn</option>
<option value="new">Tạo series mới</option>
</select>
</div>
{epubSeriesMode === "existing" && (
<div className="grid gap-2">
<label className="text-xs font-medium text-muted-foreground">Chọn series</label>
<select
value={epubSeriesId}
onChange={(e) => setEpubSeriesId(e.target.value)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="">-- Chọn series --</option>
{seriesList.map((series) => (
<option key={series.id} value={series.id}>{series.name}</option>
))}
</select>
</div>
)}
{epubSeriesMode === "new" && (
<div className="grid gap-2">
<label className="text-xs font-medium text-muted-foreground">Tên series mới</label>
<Input
value={epubSeriesName}
onChange={(e) => setEpubSeriesName(e.target.value)}
placeholder="Ví dụ: Harry Potter"
/>
</div>
)}
</div>
<div>
@@ -1604,8 +1448,6 @@ export function NovelClient() {
!epubPreviewData ||
!epubTitle.trim() ||
!epubAuthorName.trim() ||
(epubSeriesMode === "existing" && !epubSeriesId) ||
(epubSeriesMode === "new" && !epubSeriesName.trim()) ||
(epubSplitMode === "regex" && epubRegexPreset === "custom" && !epubCustomRegex.trim())
}
>
@@ -1628,9 +1470,9 @@ export function NovelClient() {
>
<DialogContent className="w-[96vw] max-w-[96vw] sm:!max-w-[920px] max-h-[85vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Import nhiều EPUB vào series</DialogTitle>
<DialogTitle>Import nhiều EPUB</DialogTitle>
<DialogDescription>
Đã chọn {pendingEpubFiles.length} file EPUB (từ file lẻ hoặc thư mục con). Mỗi file sẽ tạo thành một truyện đưc gán vào ng series.
Đã chọn {pendingEpubFiles.length} file EPUB (từ file lẻ hoặc thư mục con). Mỗi file sẽ tạo thành một truyện riêng.
</DialogDescription>
</DialogHeader>
@@ -1716,55 +1558,6 @@ export function NovelClient() {
</div>
</div>
</div>
<div className="grid gap-2">
<label className="text-sm font-medium">Series</label>
<select
value={epubSeriesMode}
onChange={(e) => {
const mode = e.target.value as "none" | "existing" | "new"
setEpubSeriesMode(mode)
if (mode !== "existing") setEpubSeriesId("")
if (mode === "new" && !epubSeriesName.trim()) {
const fallbackTitle = pendingEpubFiles[0]?.name?.replace(/\.epub$/i, "") || ""
setEpubSeriesName(fallbackTitle)
}
if (mode !== "new") setEpubSeriesName("")
}}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="none">Không gán series</option>
<option value="existing">Thêm vào series sẵn</option>
<option value="new">Tạo series mới</option>
</select>
</div>
{epubSeriesMode === "existing" && (
<div className="grid gap-2">
<label className="text-sm font-medium">Chọn series</label>
<select
value={epubSeriesId}
onChange={(e) => setEpubSeriesId(e.target.value)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="">-- Chọn series --</option>
{seriesList.map((series) => (
<option key={series.id} value={series.id}>{series.name}</option>
))}
</select>
</div>
)}
{epubSeriesMode === "new" && (
<div className="grid gap-2">
<label className="text-sm font-medium">Tên series mới</label>
<Input
value={epubSeriesName}
onChange={(e) => setEpubSeriesName(e.target.value)}
placeholder="Ví dụ: Chronicles of Narnia"
/>
</div>
)}
</div>
<DialogFooter className="sticky bottom-0 bg-background pt-2">
@@ -1773,9 +1566,7 @@ export function NovelClient() {
onClick={handleBulkEpubUpload}
disabled={
uploadingEpub ||
pendingEpubFiles.length === 0 ||
(epubSeriesMode === "existing" && !epubSeriesId) ||
(epubSeriesMode === "new" && !epubSeriesName.trim())
pendingEpubFiles.length === 0
}
>
{uploadingEpub && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
@@ -1808,14 +1599,7 @@ export function NovelClient() {
<label className="text-sm font-medium">Tên truyện</label>
<Input
value={title}
onChange={(e) => {
const nextTitle = e.target.value
const shouldSyncSeriesName = seriesMode === "new" && (!newSeriesName.trim() || newSeriesName === title)
setTitle(nextTitle)
if (shouldSyncSeriesName) {
setNewSeriesName(nextTitle)
}
}}
onChange={(e) => setTitle(e.target.value)}
placeholder="Ví dụ: Phàm Nhân Tu Tiên"
autoFocus
/>
@@ -1832,51 +1616,6 @@ export function NovelClient() {
<label className="text-sm font-medium">Tác giả gốc (Tùy chọn)</label>
<Input value={originalAuthorName} onChange={(e) => setOriginalAuthorName(e.target.value)} placeholder="Ví dụ: 忘语" />
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Series</label>
<select
value={seriesMode}
onChange={(e) => {
const mode = e.target.value as "none" | "existing" | "new"
setSeriesMode(mode)
if (mode !== "existing") setSelectedSeriesId("")
if (mode === "new" && !newSeriesName.trim()) {
setNewSeriesName(title.trim())
}
if (mode !== "new") setNewSeriesName("")
}}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="none">Không gán series</option>
<option value="existing">Chọn series sẵn</option>
<option value="new">Tạo series mới</option>
</select>
</div>
{seriesMode === "existing" && (
<div className="space-y-2">
<label className="text-sm font-medium">Chọn series</label>
<select
value={selectedSeriesId}
onChange={(e) => setSelectedSeriesId(e.target.value)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="">-- Chọn series --</option>
{seriesList.map((series) => (
<option key={series.id} value={series.id}>{series.name}</option>
))}
</select>
</div>
)}
{seriesMode === "new" && (
<div className="space-y-2">
<label className="text-sm font-medium">Tên series mới</label>
<Input
value={newSeriesName}
onChange={(e) => setNewSeriesName(e.target.value)}
placeholder="Ví dụ: Chronicles of Narnia"
/>
</div>
)}
<div className="space-y-2">
<label className="text-sm font-medium">nh bìa (Tùy chọn)</label>
<div className="flex gap-2">
@@ -1937,17 +1676,6 @@ export function NovelClient() {
<label className="text-sm font-medium">Tác giả gốc (Tùy chọn)</label>
<Input value={originalAuthorName} onChange={(e) => setOriginalAuthorName(e.target.value)} />
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Series</label>
<Input
value={editingNovel?.series?.name || "Độc lập"}
disabled
className="bg-muted"
/>
<p className="text-xs text-muted-foreground">
Không thể chỉnh sửa series tại màn hình sửa truyện.
</p>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">nh bìa (Tùy chọn)</label>
<div className="flex gap-2">
@@ -2028,7 +1756,7 @@ export function NovelClient() {
<Input
value={searchKeyword}
onChange={(e) => setSearchKeyword(e.target.value)}
placeholder="Tìm theo tên truyện, tác giả, series..."
placeholder="Tìm theo tên truyện, tác giả..."
className="pl-8"
/>
</div>
@@ -2114,7 +1842,6 @@ export function NovelClient() {
</th>
<th scope="col" className="px-5 py-4 font-semibold">Tên truyện</th>
<th scope="col" className="px-5 py-4 font-semibold">Tác giả</th>
<th scope="col" className="px-5 py-4 font-semibold">Series</th>
<th scope="col" className="px-5 py-4 font-semibold">Số chương</th>
<th scope="col" className="px-5 py-4 font-semibold">Trạng thái</th>
<th scope="col" className="px-5 py-4 text-right font-semibold">Thao tác</th>
@@ -2122,9 +1849,9 @@ export function NovelClient() {
</thead>
<tbody>
{loading ? (
<tr><td colSpan={7} className="p-8 text-center text-muted-foreground"><Loader2 className="h-6 w-6 animate-spin mx-auto" /></td></tr>
<tr><td colSpan={6} className="p-8 text-center text-muted-foreground"><Loader2 className="h-6 w-6 animate-spin mx-auto" /></td></tr>
) : filteredNovels.length === 0 ? (
<tr><td colSpan={7} className="p-8 text-center text-muted-foreground">Không truyện phù hợp với từ khóa tìm kiếm.</td></tr>
<tr><td colSpan={6} className="p-8 text-center text-muted-foreground">Không truyện phù hợp với từ khóa tìm kiếm.</td></tr>
) : (
pagedNovels.map((novel) => (
<tr key={novel.id} className="border-b border-border hover:bg-muted/30 transition-colors last:border-0">
@@ -2145,11 +1872,6 @@ export function NovelClient() {
{novel.title}
</td>
<td className="px-5 py-4 text-muted-foreground">{novel.authorName}</td>
<td className="px-5 py-4">
<span className={`inline-flex items-center justify-center rounded-full px-2.5 py-0.5 text-xs font-semibold ${novel.series ? "bg-sky-100 text-sky-700 dark:bg-sky-900/40 dark:text-sky-300" : "bg-muted text-muted-foreground"}`}>
{novel.series?.name || "Độc lập"}
</span>
</td>
<td className="px-5 py-4">
<span className="inline-flex items-center justify-center rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-semibold text-primary">
{novel.totalChapters}
@@ -2224,11 +1946,6 @@ export function NovelClient() {
<div className="p-3 flex flex-col flex-1">
<h3 className="font-semibold text-sm line-clamp-2 leading-tight mb-1" title={novel.title}>{novel.title}</h3>
<p className="text-xs text-muted-foreground mb-3">{novel.authorName}</p>
<p className="text-[11px] mb-3">
<span className={`inline-flex items-center rounded-full px-2 py-0.5 font-semibold ${novel.series ? "bg-sky-100 text-sky-700 dark:bg-sky-900/40 dark:text-sky-300" : "bg-muted text-muted-foreground"}`}>
{novel.series?.name || "Độc lập"}
</span>
</p>
<div className="mt-auto grid grid-cols-3 gap-1.5">
<Button size="sm" variant="outline" className="w-full h-7 text-xs px-0 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50" asChild>
+3 -5
View File
@@ -20,7 +20,6 @@ type HomeNovel = {
status: string
description: string
bookmarkCount: number
seriesId: string | null
updatedAt: string | null
}
@@ -51,7 +50,6 @@ type RecommendedByCountItem = {
type RankingEntry = {
id: string
seriesId: string | null
novel: HomeNovel
aggregatedViews: number
}
@@ -188,9 +186,9 @@ export default async function HomePage() {
randomNovels = [...popularItems].sort(() => Math.random() - 0.5).slice(0, 12)
latestNovels = latestItems
recentComments = []
weeklyRanking = popularItems.slice(0, 5).map((novel) => ({ id: novel.id, seriesId: novel.seriesId, novel, aggregatedViews: novel.views }))
monthlyRanking = popularItems.slice(5, 10).map((novel) => ({ id: novel.id, seriesId: novel.seriesId, novel, aggregatedViews: novel.views }))
allTimeRanking = popularItems.slice(10, 15).map((novel) => ({ id: novel.id, seriesId: novel.seriesId, novel, aggregatedViews: novel.views }))
weeklyRanking = popularItems.slice(0, 5).map((novel) => ({ id: novel.id, novel, aggregatedViews: novel.views }))
monthlyRanking = popularItems.slice(5, 10).map((novel) => ({ id: novel.id, novel, aggregatedViews: novel.views }))
allTimeRanking = popularItems.slice(10, 15).map((novel) => ({ id: novel.id, novel, aggregatedViews: novel.views }))
for (const novel of latestNovels) {
latestChapterMap.set(novel.id, {
+1 -2
View File
@@ -26,7 +26,6 @@ type BrowseNovel = {
views: number
totalChapters: number
status: string
seriesId?: string | null
}
type BrowseResponse = {
@@ -55,7 +54,7 @@ export default async function GenreDetailPage({
}
const browse = await readerApiFetch<BrowseResponse>(
`/api/novels/browse?genre=${encodeURIComponent(slug)}&sort=${sort}&page=${requestedPage}&limit=${PAGE_SIZE}&collapse_series=true`
`/api/novels/browse?genre=${encodeURIComponent(slug)}&sort=${sort}&page=${requestedPage}&limit=${PAGE_SIZE}`
)
const totalPages = Math.max(1, browse.totalPages || 1)
-20
View File
@@ -18,7 +18,6 @@ type BrowseNovel = {
views: number
totalChapters: number
status: string
seriesId?: string | null
}
type BrowseResponse = {
@@ -34,24 +33,6 @@ type GenreItem = {
slug: string
}
function collapseSeriesRows<T extends { id: string; seriesId?: string | null }>(rows: T[]): T[] {
const pickedSeries = new Set<string>()
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
}
function buildBrowsePath(params: Record<string, string>) {
const search = new URLSearchParams(params)
return `/api/novels/browse?${search.toString()}`
@@ -100,7 +81,6 @@ export default async function SearchPage({
status: statusFilter === "all" ? "" : statusFilter,
page: String(requestedPage),
limit: String(PAGE_SIZE),
collapse_series: "true",
})
)
+27 -88
View File
@@ -1,6 +1,5 @@
import { notFound } from "next/navigation"
import Link from "next/link"
import { BookOpen, Eye, BookMarked, User, Clock, Layers } from "lucide-react"
import { formatViews } from "@/lib/utils"
import { GenreBadge } from "@/components/genre-badge"
import { StarRating } from "@/components/star-rating"
@@ -18,15 +17,6 @@ type NovelGenre = {
slug: string
}
type SeriesNovel = {
id: string
slug: string
title: string
status: string
totalChapters: number
coverUrl: string | null
}
type NovelDetail = {
id: string
title: string
@@ -41,14 +31,7 @@ type NovelDetail = {
views: number
ratingCount: number
bookmarkCount: number
seriesId: string | null
genres: NovelGenre[]
series: {
id: string
name: string
slug: string
novels: SeriesNovel[]
} | null
}
type ChaptersResponse = {
@@ -100,43 +83,29 @@ export default async function NovelDetailPage({
let totalChapters = 0
let totalPages = 1
let firstChapterNumber: number | undefined
let seriesVolumes: Array<{
id: string
slug: string
title: string
status: string
totalChapters: number
coverUrl: string | null
}> = []
const [firstChapterData, commentsData, chapterCommentsData, chaptersData] = await Promise.all([
readerApiFetch<ChaptersResponse>(`/api/truyen/${encodeURIComponent(novel.id)}/chapters?page=1&limit=1`),
readerApiFetch<CommentsResponse>(`/api/truyen/${encodeURIComponent(novel.id)}/comments?page=1&limit=50`),
readerApiFetch<CommentsResponse>(`/api/truyen/${encodeURIComponent(novel.id)}/comments?scope=chapter&page=1&limit=50`),
novel.seriesId
? Promise.resolve(null)
: readerApiFetch<ChaptersResponse>(`/api/truyen/${encodeURIComponent(novel.id)}/chapters?page=${currentPage}&limit=${limit}`),
readerApiFetch<ChaptersResponse>(`/api/truyen/${encodeURIComponent(novel.id)}/chapters?page=${currentPage}&limit=${limit}`),
])
firstChapterNumber = firstChapterData.chapters[0]?.number
if (novel.seriesId) {
seriesVolumes = novel.series?.novels || []
} else if (chaptersData) {
totalChapters = chaptersData.totalChapters
totalPages = Math.max(1, chaptersData.totalPages || 1)
formattedChapters = chaptersData.chapters.map((chapter) => ({
id: chapter.id,
novelId: novel.id,
number: chapter.number,
volumeNumber: chapter.volumeNumber ?? null,
volumeTitle: chapter.volumeTitle ?? null,
volumeChapterNumber: chapter.volumeChapterNumber ?? null,
title: chapter.title,
createdAt: chapter.createdAt ? chapter.createdAt.split("T")[0] : "",
views: chapter.views || 0,
content: "",
}))
}
totalChapters = chaptersData.totalChapters
totalPages = Math.max(1, chaptersData.totalPages || 1)
formattedChapters = chaptersData.chapters.map((chapter) => ({
id: chapter.id,
novelId: novel.id,
number: chapter.number,
volumeNumber: chapter.volumeNumber ?? null,
volumeTitle: chapter.volumeTitle ?? null,
volumeChapterNumber: chapter.volumeChapterNumber ?? null,
title: chapter.title,
createdAt: chapter.createdAt ? chapter.createdAt.split("T")[0] : "",
views: chapter.views || 0,
content: "",
}))
const comments = commentsData.comments.map((comment) => ({
id: comment.id,
@@ -242,48 +211,18 @@ export default async function NovelDetailPage({
<div className="text-sm leading-relaxed text-foreground/80 whitespace-pre-wrap">{novel.description || ""}</div>
</section>
{/* Chapter list or series volumes */}
{novel.seriesId ? (
<section className="mt-8">
<h2 className="mb-3 text-lg font-bold text-foreground">Danh Sách Quyển</h2>
<div className="rounded-lg border border-border bg-card divide-y divide-border">
{seriesVolumes.map((volume, idx) => (
<Link
key={volume.id}
href={`/truyen/${volume.slug}`}
className={`flex items-center gap-4 px-4 py-3 hover:bg-muted/40 transition-colors ${volume.id === novel.id ? "bg-primary/5" : ""}`}
>
<span className="w-8 text-center text-sm font-semibold text-muted-foreground">{idx + 1}</span>
<img
src={volume.coverUrl || "/default-cover.svg"}
alt={volume.title}
className="h-14 w-10 rounded bg-muted object-contain"
/>
<div className="min-w-0 flex-1">
<p className="font-medium text-foreground truncate">{volume.title}</p>
<p className="text-xs text-muted-foreground">{volume.totalChapters} chương</p>
</div>
<span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold ${getNovelStatusBadgeClass(volume.status)}`}>
{volume.status}
</span>
</Link>
))}
</div>
</section>
) : (
<section className="mt-8">
<h2 className="mb-3 text-lg font-bold text-foreground">Danh Sách Chương</h2>
<div className="rounded-lg border border-border bg-card">
<ChapterList
chapters={formattedChapters as any}
novelSlug={novel.slug}
currentPage={currentPage}
totalPages={totalPages}
totalChapters={totalChapters}
/>
</div>
</section>
)}
<section className="mt-8">
<h2 className="mb-3 text-lg font-bold text-foreground">Danh Sách Chương</h2>
<div className="rounded-lg border border-border bg-card">
<ChapterList
chapters={formattedChapters as any}
novelSlug={novel.slug}
currentPage={currentPage}
totalPages={totalPages}
totalChapters={totalChapters}
/>
</div>
</section>
{/* Comments */}
<section className="mt-8">