Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-03-11 17:02:31 +07:00
parent 1139125460
commit 5686753ab7
42 changed files with 4659 additions and 309 deletions
+45 -5
View File
@@ -1,9 +1,45 @@
import { getServerSession } from "next-auth"
import { authOptions } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
export default async function ModDashboardPage() {
const session = await getServerSession(authOptions)
const novelWhere = session?.user.role === "ADMIN"
? {}
: {
OR: [
{ uploaderId: session?.user.id },
{ uploaderId: null },
],
}
const [novelCount, novelViewsAgg, commentCount, seriesCount] = await Promise.all([
prisma.novel.count({ where: novelWhere }),
prisma.novel.aggregate({
where: novelWhere,
_sum: { views: true },
}),
prisma.comment.count({
where: {
novel: novelWhere,
},
}),
prisma.series.count({
where: session?.user.role === "ADMIN"
? {}
: {
OR: [
{ novels: { some: { uploaderId: session?.user.id } } },
{ novels: { some: { uploaderId: null } } },
{ novels: { none: {} } },
],
},
}),
])
const totalViews = novelViewsAgg._sum.views || 0
return (
<div>
<h1 className="text-2xl font-bold mb-4">Xin chào, {session?.user.name}</h1>
@@ -11,18 +47,22 @@ 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-3 gap-4">
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4">
<div className="rounded-xl border bg-card text-card-foreground shadow p-6">
<h3 className="font-semibold text-lg">Truyện của bạn</h3>
<p className="text-3xl font-bold mt-2">0</p>
<h3 className="font-semibold text-lg">Tổng truyện</h3>
<p className="text-3xl font-bold mt-2">{novelCount}</p>
</div>
<div className="rounded-xl border bg-card text-card-foreground shadow p-6">
<h3 className="font-semibold text-lg">Tổng lượt xem</h3>
<p className="text-3xl font-bold mt-2">0</p>
<p className="text-3xl font-bold mt-2">{totalViews}</p>
</div>
<div className="rounded-xl border bg-card text-card-foreground shadow p-6">
<h3 className="font-semibold text-lg">Bình luận mới</h3>
<p className="text-3xl font-bold mt-2">0</p>
<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>