Skip to content

Commit

Permalink
fix: comment can not be blank and duplicate (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
youyc22 authored Jan 13, 2025
1 parent 0fcfbe6 commit 9394cb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
31 changes: 31 additions & 0 deletions src/app/ShareSite/CoursePage/DiscussDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ const DiscussDrawer: React.FC<CourseProps> = ({

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,
Expand All @@ -339,6 +354,22 @@ const DiscussDrawer: React.FC<CourseProps> = ({

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,
Expand Down
12 changes: 0 additions & 12 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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秒再发起下一个请求
}
});
};
// 初次请求
Expand Down Expand Up @@ -519,12 +513,6 @@ const App: React.FC = () => {
console.error("Failed to load avatar:", error);
message.error("加载头像失败");
}
})
.finally(() => {
// 这里调用下次请求
if (isMounted) {
setTimeout(fetchAvatar, 500); // 请求完成后 1 秒再发起下一个请求
}
});
};

Expand Down

0 comments on commit 9394cb9

Please sign in to comment.