From 9394cb9d0461edc0f4e5414b272c00c6ad93c82d Mon Sep 17 00:00:00 2001 From: Yichen You <125688164+youyc22@users.noreply.github.com> Date: Mon, 13 Jan 2025 22:25:51 +0800 Subject: [PATCH] fix: comment can not be blank and duplicate (#2169) --- .../ShareSite/CoursePage/DiscussDrawer.tsx | 31 +++++++++++++++++++ src/app/index.tsx | 12 ------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/app/ShareSite/CoursePage/DiscussDrawer.tsx b/src/app/ShareSite/CoursePage/DiscussDrawer.tsx index 69f76a591..73f8f6335 100644 --- a/src/app/ShareSite/CoursePage/DiscussDrawer.tsx +++ b/src/app/ShareSite/CoursePage/DiscussDrawer.tsx @@ -318,6 +318,21 @@ const DiscussDrawer: React.FC = ({ const handleAddCourseComment = async (parent_uuid?: string) => { try { + if (!newComment || !newComment.trim()) { + message.warning("评论内容不能为空"); + return; + } + + const isDuplicate = comments.some( + (comment) => + comment.comment === newComment && comment.user_uuid === user.uuid, + ); + + if (isDuplicate) { + message.warning("请勿重复发布相同评论"); + return; + } + const response = await axios.post(`/course/comments/add`, { comment: newComment, course_uuid: course_uuid, @@ -339,6 +354,22 @@ const DiscussDrawer: React.FC = ({ const handleUpdateCourseComment = async () => { try { + if (!updateComment || !updateComment.trim()) { + message.warning("评论内容不能为空"); + return; + } + + // 获取原评论内容 + const originalComment = comments.find( + (item) => item.uuid === updateCommentUuid, + ); + + // 检查内容是否有变化 + if (originalComment && originalComment.comment === updateComment.trim()) { + message.info("评论内容未发生变化"); + return; + } + const response = await axios.post(`/course/comments/update`, { comment: updateComment, comment_uuid: updateCommentUuid, diff --git a/src/app/index.tsx b/src/app/index.tsx index b699ac156..9f28c2067 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -104,12 +104,6 @@ const App: React.FC = () => { console.error("Failed to load avatar:", error); message.error("加载头像失败"); } - }) - .finally(() => { - // 调用下次请求 - if (isMounted) { - setTimeout(fetchAvatar, 500); // 请求完成后延迟0.5秒再发起下一个请求 - } }); }; // 初次请求 @@ -519,12 +513,6 @@ const App: React.FC = () => { console.error("Failed to load avatar:", error); message.error("加载头像失败"); } - }) - .finally(() => { - // 这里调用下次请求 - if (isMounted) { - setTimeout(fetchAvatar, 500); // 请求完成后 1 秒再发起下一个请求 - } }); };