|
|
@@ -36,16 +36,19 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
const actualMvId = contentId;
|
|
|
const [comments, setComments] = useState<ApiComment[]>([]);
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
-
|
|
|
+ const getCommentFun = async () => {
|
|
|
+ setLoading(true);
|
|
|
+ const res: ApiResponse = await getCommentListByIdType({
|
|
|
+ contentId: actualMvId,
|
|
|
+ type
|
|
|
+ });
|
|
|
+ setComments(res.data);
|
|
|
+ }
|
|
|
useEffect(() => {
|
|
|
- const fetchComments = async () => {
|
|
|
+ const fetchComments = () => {
|
|
|
if (actualMvId) {
|
|
|
try {
|
|
|
- const res: ApiResponse = await getCommentListByIdType({
|
|
|
- contentId: actualMvId,
|
|
|
- type
|
|
|
- });
|
|
|
- setComments(res.data);
|
|
|
+ getCommentFun()
|
|
|
} catch (error) {
|
|
|
console.error('获取评论失败:', error);
|
|
|
} finally {
|
|
|
@@ -73,15 +76,10 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
const handleReplySubmit = () => {
|
|
|
setActiveCommentBox(null);
|
|
|
// 提交回复后重新获取评论列表
|
|
|
- const fetchComments = async () => {
|
|
|
+ const fetchComments = () => {
|
|
|
if (actualMvId) {
|
|
|
try {
|
|
|
- setLoading(true);
|
|
|
- const res: ApiResponse = await getCommentListByIdType({
|
|
|
- contentId: actualMvId,
|
|
|
- type
|
|
|
- });
|
|
|
- setComments(res.data);
|
|
|
+ getCommentFun()
|
|
|
} catch (error) {
|
|
|
console.error('获取评论失败:', error);
|
|
|
} finally {
|
|
|
@@ -98,12 +96,8 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
const fetchComments = async () => {
|
|
|
if (actualMvId) {
|
|
|
try {
|
|
|
- setLoading(true);
|
|
|
- const res: ApiResponse = await getCommentListByIdType({
|
|
|
- contentId: actualMvId,
|
|
|
- type
|
|
|
- });
|
|
|
- setComments(res.data);
|
|
|
+
|
|
|
+ getCommentFun()
|
|
|
} catch (error) {
|
|
|
console.error('获取评论失败:', error);
|
|
|
} finally {
|
|
|
@@ -119,16 +113,16 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
try {
|
|
|
// 调用API进行点赞
|
|
|
const res = await addLikeCount(commentId);
|
|
|
-
|
|
|
+
|
|
|
// 更新本地状态
|
|
|
- setComments(prevComments =>
|
|
|
- prevComments.map(comment =>
|
|
|
- comment.id === commentId
|
|
|
- ? { ...comment, likeCount: comment.likeCount + 1 }
|
|
|
+ setComments(prevComments =>
|
|
|
+ prevComments.map(comment =>
|
|
|
+ comment.id === commentId
|
|
|
+ ? { ...comment, likeCount: comment.likeCount + 1 }
|
|
|
: comment
|
|
|
)
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
console.log('点赞成功:', res);
|
|
|
} catch (error) {
|
|
|
console.error('点赞失败:', error);
|
|
|
@@ -140,16 +134,16 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
try {
|
|
|
// 调用API取消点赞
|
|
|
const res = await cancelLikeCount(commentId);
|
|
|
-
|
|
|
+
|
|
|
// 更新本地状态
|
|
|
- setComments(prevComments =>
|
|
|
- prevComments.map(comment =>
|
|
|
- comment.id === commentId
|
|
|
- ? { ...comment, likeCount: Math.max(0, comment.likeCount - 1) }
|
|
|
+ setComments(prevComments =>
|
|
|
+ prevComments.map(comment =>
|
|
|
+ comment.id === commentId
|
|
|
+ ? { ...comment, likeCount: Math.max(0, comment.likeCount - 1) }
|
|
|
: comment
|
|
|
)
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
console.log('取消点赞成功:', res);
|
|
|
} catch (error) {
|
|
|
console.error('取消点赞失败:', error);
|
|
|
@@ -180,7 +174,7 @@ const Rank_Recommend_body_list_Comment_list = ({ contentId, type }: CommentListP
|
|
|
<div className="Rank_Recommend_body_list_Comment_list_ttitle">
|
|
|
精彩评论 ({comments.length})
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
{comments.length > 0 ? (
|
|
|
comments.map((item, index) => (
|
|
|
<div
|