import useSWR from "swr"; import { BlogCommentTool } from "./BlogCommentTool"; import { BlogApi } from "@/lib/api"; export function BlogComments({ blogId }: { blogId: string }) { const { data, isLoading, error } = useSWR( `/api/blog/${blogId}/comments`, () => BlogApi.getComments(blogId), ) return ( data &&

评论 {data.length}

{ data.filter(d => !d.parentId) .map(d => (

{d.user ? d.user : '匿名'}

{d.content}

{new Date(d.createdAt).toLocaleString()}

未知

回复

{ data.filter(c => c.parentId === d.id).length > 0 && (
{ data.filter(c => c.parentId === d.id).map(c => (

{c.user ? c.user : '匿名'}

{c.content}

{new Date().toLocaleString()}

未知

)) }
) }
)) }
) }