"use client" import { Heart } from "lucide-react" import { useState } from "react" import { generateId } from "@/lib/id" import type { Comment } from "@/lib/types" import { useRequireAuth } from "@/lib/use-require-auth" import { useAuthStore } from "@/store/auth" import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar" import { Button } from "./ui/button" import { Textarea } from "./ui/textarea" interface PostCommentsProps { initialComments: Comment[] postId: string } export function PostComments({ initialComments, postId }: PostCommentsProps) { const [comments, setComments] = useState(initialComments) const [content, setContent] = useState("") const { requireAuth } = useRequireAuth() const user = useAuthStore((s) => s.user) return (

评论 ({comments.length})

{ event.preventDefault() requireAuth(() => { const nextContent = content.trim() if (!nextContent) return if (!user) return const createdAt = new Date().toISOString() setComments((prev) => [ ...prev, { id: generateId(`comment-${postId}`), postId, author: user, content: nextContent, likeCount: 0, liked: false, createdAt, }, ]) setContent("") }) }} >