mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
✨ feat: 优化评论功能,添加登录提示和国际化支持,重构相关组件
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 10s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 10s
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useToUserProfile } from "@/hooks/use-route";
|
||||
import { useToLogin, useToUserProfile } from "@/hooks/use-route";
|
||||
import { User } from "@/models/user";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useState } from "react";
|
||||
@ -29,7 +29,9 @@ export function CommentItem(
|
||||
}
|
||||
) {
|
||||
const t = useTranslations("Comment")
|
||||
const toUserProfile = useToUserProfile();
|
||||
const commonT = useTranslations('Common')
|
||||
const clickToUserProfile = useToUserProfile();
|
||||
const clickToLogin = useToLogin();
|
||||
const { confirming, onClick, onBlur } = useDoubleConfirm();
|
||||
|
||||
const [likeCount, setLikeCount] = useState(comment.likeCount);
|
||||
@ -43,6 +45,19 @@ export function CommentItem(
|
||||
const [showEditInput, setShowEditInput] = useState(false);
|
||||
|
||||
const handleToggleLike = () => {
|
||||
if (!user) {
|
||||
toast.error(t("login_required"), {
|
||||
action: <div className="flex justify-end">
|
||||
<button
|
||||
onClick={clickToLogin}
|
||||
className="ml-0 text-left bg-red-400 text-white dark:text-black px-3 py-1 rounded font-semibold hover:bg-red-600 transition-colors"
|
||||
>
|
||||
{commonT("login")}
|
||||
</button>
|
||||
</div>,
|
||||
});
|
||||
return;
|
||||
}
|
||||
toggleLike(
|
||||
{ targetType: TargetType.Comment, targetId: comment.id }
|
||||
).then(res => {
|
||||
@ -133,7 +148,7 @@ export function CommentItem(
|
||||
}
|
||||
{
|
||||
parentComment &&
|
||||
<>{t("reply")} <button onClick={() => toUserProfile(parentComment.user.nickname)} className="text-primary">{parentComment?.user.nickname}</button>: </>
|
||||
<>{t("reply")} <button onClick={() => clickToUserProfile(parentComment.user.nickname)} className="text-primary">{parentComment?.user.nickname}</button>: </>
|
||||
}
|
||||
{comment.content}
|
||||
</p>
|
||||
|
Reference in New Issue
Block a user