feat: 添加评论动画样式和登录组件

This commit is contained in:
2025-09-10 09:59:22 +08:00
parent 4fb39110ad
commit 052d72c8c0
2 changed files with 133 additions and 126 deletions

View File

@ -36,6 +36,7 @@ export function CommentItem(
const [likeCount, setLikeCount] = useState(comment.likeCount); const [likeCount, setLikeCount] = useState(comment.likeCount);
const [liked, setLiked] = useState(comment.isLiked); const [liked, setLiked] = useState(comment.isLiked);
const [canClickLike, setCanClickLike] = useState(true);
const [isPrivate, setIsPrivate] = useState(comment.isPrivate); const [isPrivate, setIsPrivate] = useState(comment.isPrivate);
const [replyCount, setReplyCount] = useState(comment.replyCount); const [replyCount, setReplyCount] = useState(comment.replyCount);
const [showReplies, setShowReplies] = useState(false); const [showReplies, setShowReplies] = useState(false);
@ -45,6 +46,10 @@ export function CommentItem(
const [showEditInput, setShowEditInput] = useState(false); const [showEditInput, setShowEditInput] = useState(false);
const handleToggleLike = () => { const handleToggleLike = () => {
if (!canClickLike) {
return;
}
setCanClickLike(false);
if (!user) { if (!user) {
toast.error(t("login_required"), { toast.error(t("login_required"), {
action: <div className="flex justify-end"> action: <div className="flex justify-end">
@ -58,6 +63,7 @@ export function CommentItem(
}); });
return; return;
} }
setLiked(!liked) // 提前转换状态,让用户觉得响应很快
toggleLike( toggleLike(
{ targetType: TargetType.Comment, targetId: comment.id } { targetType: TargetType.Comment, targetId: comment.id }
).then(res => { ).then(res => {
@ -67,6 +73,7 @@ export function CommentItem(
}).catch(error => { }).catch(error => {
toast.error(t("like_failed") + ": " + error.message); toast.error(t("like_failed") + ": " + error.message);
}); });
setCanClickLike(true);
} }
const reloadReplies = () => { const reloadReplies = () => {