feat: 添加评论功能,包括评论输入、评论列表和评论项组件,支持层级深度和私密评论

This commit is contained in:
2025-07-31 08:03:19 +08:00
parent 92c2a58e80
commit 94aa4f1b1f
23 changed files with 303 additions and 53 deletions

View File

@ -0,0 +1,41 @@
"use client";
import type { Comment } from "@/models/comment";
import { CommentInput } from "@/components/comment/comment-input";
import { useEffect, useState } from "react";
import { listComments } from "@/api/comment";
import { OrderBy } from "@/models/common";
interface CommentAreaProps {
targetType: 'post' | 'page';
targetId: number;
}
export default function CommentSection(props: CommentAreaProps) {
const { targetType, targetId } = props;
const [comments, setComments] = useState<Comment[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [newComment, setNewComment] = useState<string>("");
useEffect(() => {
listComments({ page: 1, size: 10, orderBy: OrderBy.CreatedAt, desc: true }, 1)
.then(response => {
setComments(response.data);
})
.catch(err => {
setError("加载评论失败,请稍后再试。");
console.error("Error loading comments:", err);
})
.finally(() => {
setLoading(false);
});
}, [targetType, targetId]);
return (
<div>
<h2></h2>
<CommentInput />
</div>
);
}