-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import prisma from "@/lib/prisma"; | ||
import { notFound, redirect } from "next/navigation"; | ||
|
||
const REPLIES_PER_PAGE = parseInt(process.env.REPLIES_PER_PAGE ?? "10", 10); | ||
|
||
export default async function Page({ params }: { params: { rid: string } }) { | ||
const id = parseInt(params.rid, 10); | ||
if (Number.isNaN(id)) notFound(); | ||
const { discussionId } = | ||
(await prisma.reply.findUnique({ | ||
select: { discussionId: true }, | ||
where: { id }, | ||
})) ?? notFound(); | ||
const pages = Math.ceil( | ||
(await prisma.reply.count({ | ||
where: { id: { lte: id }, discussionId }, | ||
})) / REPLIES_PER_PAGE | ||
); | ||
return redirect(`/${discussionId}/${pages}#${params.rid}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters