Skip to content

Commit

Permalink
回复的短链
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Jun 29, 2023
1 parent 2f0e741 commit 359e59c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/viewer/src/app/r/[rid]/page.tsx
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}`);
}
5 changes: 4 additions & 1 deletion packages/viewer/src/components/replies/Reply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function Reply({
}>) {
const [userId, setUserId] = useState<number | null>(null);
return (
<div className={reply.id && userId ? "my-5m" : undefined}>
<div
className={reply.id && userId ? "my-5m" : undefined}
id={(reply.id ?? 0).toString()}
>
{reply.id && userId && (
<ContextViewer
discussionAuthor={discussion.authorId}
Expand Down

0 comments on commit 359e59c

Please sign in to comment.