实现响应式导航栏组件
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
'use client'
|
||||
import {useProfileStore} from '@/components/providers/StoreProvider'
|
||||
import {useProfileStore} from '@/app/stores'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger} from '@/components/ui/dropdown-menu'
|
||||
import {Avatar, AvatarFallback, AvatarImage} from '@/components/ui/avatar'
|
||||
import {LogOutIcon, UserIcon, UserPenIcon} from 'lucide-react'
|
||||
import {LoaderIcon, LogOutIcon, UserIcon, UserPenIcon} from 'lucide-react'
|
||||
import {usePathname, useRouter} from 'next/navigation'
|
||||
import {logout} from '@/actions/auth'
|
||||
import {useState} from 'react'
|
||||
import {HoverCard, HoverCardContent, HoverCardTrigger} from '@/components/ui/hover-card'
|
||||
import {User} from '@/lib/models'
|
||||
|
||||
export default function UserCenter() {
|
||||
type UserCenterProps = {
|
||||
profile: User
|
||||
}
|
||||
|
||||
export default function UserCenter(props: UserCenterProps) {
|
||||
const router = useRouter()
|
||||
|
||||
// 登录控制
|
||||
const profile = useProfileStore(store => store.profile)
|
||||
const refreshProfile = useProfileStore(store => store.refreshProfile)
|
||||
const doLogout = async () => {
|
||||
const resp = await logout()
|
||||
@@ -31,13 +33,7 @@ export default function UserCenter() {
|
||||
}
|
||||
}
|
||||
|
||||
return !profile ? (
|
||||
<Button
|
||||
theme="fail"
|
||||
onClick={() => router.push('/login')}>
|
||||
去登录
|
||||
</Button>
|
||||
) : (
|
||||
return (
|
||||
<HoverCard openDelay={150} closeDelay={150}>
|
||||
<HoverCardTrigger>
|
||||
<Button
|
||||
@@ -46,10 +42,10 @@ export default function UserCenter() {
|
||||
onClick={toAdminPage}
|
||||
>
|
||||
<Avatar>
|
||||
<AvatarImage src={profile.avatar} alt="avatar"/>
|
||||
<AvatarImage src={props.profile.avatar} alt="avatar"/>
|
||||
<AvatarFallback className="bg-primary-muted"><UserIcon/></AvatarFallback>
|
||||
</Avatar>
|
||||
<span>{profile.name}</span>
|
||||
<span>{props.profile.name}</span>
|
||||
</Button>
|
||||
</HoverCardTrigger>
|
||||
<HoverCardContent className="w-36 p-1" align="end">
|
||||
|
||||
Reference in New Issue
Block a user