mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-25 18:46:23 +00:00
refactor: 移除组件中的用户属性,改为使用上下文中的用户信息
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 9s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 9s
This commit is contained in:
@ -10,11 +10,11 @@ import { Label } from "@/components/ui/label";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { getGravatarUrl } from "@/utils/common/gravatar";
|
||||
import { getFirstCharFromUser } from "@/utils/common/username";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
|
||||
|
||||
export function CommentInput(
|
||||
{
|
||||
user,
|
||||
onCommentSubmitted,
|
||||
initContent = "",
|
||||
initIsPrivate = false,
|
||||
@ -22,7 +22,6 @@ export function CommentInput(
|
||||
isUpdate = false,
|
||||
initShowClientInfo = true
|
||||
}: {
|
||||
user: User | null,
|
||||
onCommentSubmitted: ({ commentContent, isPrivate, showClientInfo }: { commentContent: string, isPrivate: boolean, showClientInfo: boolean }) => void,
|
||||
initContent?: string,
|
||||
initIsPrivate?: boolean,
|
||||
@ -31,6 +30,7 @@ export function CommentInput(
|
||||
initShowClientInfo?: boolean
|
||||
}
|
||||
) {
|
||||
const {user} = useAuth();
|
||||
const t = useTranslations('Comment')
|
||||
const commonT = useTranslations('Common')
|
||||
const clickToLogin = useToLogin()
|
||||
|
@ -15,11 +15,11 @@ import { formatDateTime } from "@/utils/common/datetime";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { getGravatarUrl } from "@/utils/common/gravatar";
|
||||
import { getFirstCharFromUser } from "@/utils/common/username";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
|
||||
|
||||
export function CommentItem(
|
||||
{
|
||||
loginUser,
|
||||
comment,
|
||||
parentComment,
|
||||
onCommentDelete,
|
||||
@ -27,7 +27,6 @@ export function CommentItem(
|
||||
setActiveInputId,
|
||||
onReplySubmitted // 评论区计数更新用
|
||||
}: {
|
||||
loginUser: User | null,
|
||||
comment: Comment,
|
||||
parentComment: Comment | null,
|
||||
onCommentDelete: ({ commentId }: { commentId: number }) => void,
|
||||
@ -36,6 +35,7 @@ export function CommentItem(
|
||||
onReplySubmitted: ({ commentContent, isPrivate }: { commentContent: string, isPrivate: boolean }) => void,
|
||||
}
|
||||
) {
|
||||
const {user} = useAuth();
|
||||
const locale = useLocale();
|
||||
const t = useTranslations("Comment");
|
||||
const commonT = useTranslations("Common");
|
||||
@ -57,7 +57,7 @@ export function CommentItem(
|
||||
return;
|
||||
}
|
||||
setCanClickLike(false);
|
||||
if (!loginUser) {
|
||||
if (!user) {
|
||||
toast.error(t("login_required"), {
|
||||
action: {
|
||||
label: commonT("login"),
|
||||
@ -236,7 +236,7 @@ export function CommentItem(
|
||||
</button>
|
||||
|
||||
{/* 编辑和删除按钮 仅自己的评论可见 */}
|
||||
{loginUser?.id === commentState.user.id && (
|
||||
{user?.id === commentState.user.id && (
|
||||
<>
|
||||
<button
|
||||
title={t("edit")}
|
||||
@ -276,13 +276,11 @@ export function CommentItem(
|
||||
</div>
|
||||
{/* 这俩输入框一次只能显示一个 */}
|
||||
{activeInput && activeInput.type === 'reply' && activeInput.id === commentState.id && <CommentInput
|
||||
user={loginUser}
|
||||
onCommentSubmitted={onReply}
|
||||
initIsPrivate={commentState.isPrivate}
|
||||
placeholder={`${t("reply")} ${commentState.user.nickname || commentState.user.username} :`}
|
||||
/>}
|
||||
{activeInput && activeInput.type === 'edit' && activeInput.id === commentState.id && <CommentInput
|
||||
user={loginUser}
|
||||
initContent={commentState.content}
|
||||
initIsPrivate={commentState.isPrivate}
|
||||
onCommentSubmitted={onCommentEdit}
|
||||
@ -297,7 +295,6 @@ export function CommentItem(
|
||||
{replies.map((reply) => (
|
||||
<CommentItem
|
||||
key={reply.id}
|
||||
loginUser={loginUser}
|
||||
comment={reply}
|
||||
parentComment={commentState}
|
||||
onCommentDelete={onReplyDelete}
|
||||
|
@ -109,7 +109,6 @@ export function CommentSection(
|
||||
<Separator className="my-16" />
|
||||
<div className="font-bold text-2xl">{t("comment")} ({totalCommentCount})</div>
|
||||
<CommentInput
|
||||
user={user}
|
||||
onCommentSubmitted={onCommentSubmitted}
|
||||
/>
|
||||
<div className="mt-4">
|
||||
@ -118,7 +117,6 @@ export function CommentSection(
|
||||
<div key={comment.id} className="" style={{ animationDelay: `${idx * 60}ms` }}>
|
||||
<Separator className="my-2" />
|
||||
<CommentItem
|
||||
loginUser={user}
|
||||
comment={comment}
|
||||
parentComment={null}
|
||||
onCommentDelete={onCommentDelete}
|
||||
|
@ -31,13 +31,11 @@ import {
|
||||
import { User } from "@/models/user"
|
||||
import { getGravatarFromUser } from "@/utils/common/gravatar"
|
||||
import { getFallbackAvatarFromUsername } from "@/utils/common/username"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
|
||||
export function NavUser({
|
||||
user,
|
||||
}: {
|
||||
user?: User
|
||||
}) {
|
||||
export function NavUser({}: {}) {
|
||||
const { isMobile } = useSidebar()
|
||||
const {user} = useAuth();
|
||||
if (!user) return null
|
||||
return (
|
||||
<SidebarMenu>
|
||||
|
Reference in New Issue
Block a user