Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: comments can not be blank and duplicate #2169

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading