mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 20:15:31 -04:00
5a1636baa3
- Replace Biome with oxlint + oxfmt (OXC toolchain) for linting and formatting - Add .oxlintrc.json and .oxfmtrc.json configuration files - Update VS Code settings and devcontainer to use oxc-vscode extension - Remove contact form, Resend email integration, and related server action/schema - Remove unused UI components (accordion, alert, card, tabs, toggle, etc.)
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { headers } from "next/headers";
|
|
|
|
import { auth } from "@/lib/auth";
|
|
import { type CommentWithUser, getComments } from "@/lib/server/comments";
|
|
|
|
import { NewCommentForm } from "./comment-form";
|
|
import { CommentThread } from "./comment-thread";
|
|
import { SignIn } from "./sign-in";
|
|
|
|
const Comments = async ({ slug }: { slug: string }) => {
|
|
const session = await auth.api.getSession({
|
|
headers: await headers(),
|
|
});
|
|
|
|
const comments = await getComments(slug);
|
|
|
|
const commentsByParentId = comments.reduce(
|
|
(acc, comment) => {
|
|
const parentId = comment.parentId || "root";
|
|
if (!acc[parentId]) {
|
|
acc[parentId] = [];
|
|
}
|
|
acc[parentId].push(comment);
|
|
return acc;
|
|
},
|
|
{} as Record<string, CommentWithUser[]>,
|
|
);
|
|
|
|
const rootComments = commentsByParentId.root || [];
|
|
|
|
return (
|
|
<>
|
|
{session ? (
|
|
<NewCommentForm slug={slug} />
|
|
) : (
|
|
<div className="bg-muted/40 flex flex-col items-center justify-center gap-y-4 rounded-lg p-6">
|
|
<p className="text-center font-medium">Join the discussion by signing in:</p>
|
|
<SignIn callbackPath={`/${slug}#comments`} />
|
|
</div>
|
|
)}
|
|
|
|
{rootComments.length > 0 ? (
|
|
<div className="space-y-6">
|
|
{rootComments.map((comment: CommentWithUser) => (
|
|
<CommentThread
|
|
key={comment.id}
|
|
comment={comment}
|
|
replies={commentsByParentId[comment.id] || []}
|
|
allComments={commentsByParentId}
|
|
/>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<div className="text-foreground/80 py-8 text-center text-lg font-medium tracking-tight">
|
|
Be the first to comment!
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export { Comments };
|