Skip to content

Commit

Permalink
用户页面中添加陶片数量统计
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Aug 1, 2023
1 parent 552491a commit 613c304
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/viewer/src/app/user/[uid]/UserStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ function Placeholder() {
}

export default function UserStatistics({ uid }: { uid: number }) {
const { data, isLoading } = useSWR<{ discussions: number; replies: number }>(
`/user/${uid}/statistics`,
fetcher,
);
const { data, isLoading } = useSWR<{
discussions: number;
replies: number;
judgements: number;
}>(`/user/${uid}/statistics`, fetcher);
return (
<>
<span className="fw-medium">发帖</span>{" "}
{isLoading ? <Placeholder /> : data?.discussions}
<span className="fw-medium ms-2x">回帖</span>{" "}
{isLoading ? <Placeholder /> : data?.replies}
<span className="fw-medium ms-2x">陶片</span>{" "}
{isLoading ? <Placeholder /> : data?.judgements}
</>
);
}
5 changes: 3 additions & 2 deletions packages/viewer/src/app/user/[uid]/statistics/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export async function GET(
{ params }: { params: { uid: string } },
) {
const uid = parseInt(params.uid, 10);
const [discussions, replies] = await Promise.all([
const [discussions, replies, judgements] = await Promise.all([
prisma.discussion.count({
where: { snapshots: { some: { authorId: uid } } },
}),
prisma.reply.count({ where: { authorId: uid } }),
prisma.judgement.count({ where: { userId: uid } }),
]);
return NextResponse.json({ discussions, replies });
return NextResponse.json({ discussions, replies, judgements });
}

0 comments on commit 613c304

Please sign in to comment.