perf: nav bar avatar

This commit is contained in:
codytseng
2025-01-13 17:09:20 +08:00
parent 0f8a5403cd
commit d0350c6ad3

View File

@@ -1,12 +1,20 @@
import { generateImageByPubkey } from '@/lib/pubkey'
import { cn } from '@/lib/utils'
import { usePrimaryPage } from '@/PageManager'
import { useNostr } from '@/providers/NostrProvider'
import { UserRound } from 'lucide-react'
import { SimpleUserAvatar } from '../UserAvatar'
import { useMemo } from 'react'
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'
import { Skeleton } from '../ui/skeleton'
import BottomNavigationBarItem from './BottomNavigationBarItem'
export default function AccountButton() {
const { navigate, current } = usePrimaryPage()
const { pubkey } = useNostr()
const { pubkey, profile } = useNostr()
const defaultAvatar = useMemo(
() => (profile?.pubkey ? generateImageByPubkey(profile.pubkey) : ''),
[profile]
)
return (
<BottomNavigationBarItem
@@ -16,11 +24,18 @@ export default function AccountButton() {
active={current === 'me'}
>
{pubkey ? (
<SimpleUserAvatar
userId={pubkey}
size="small"
className={current === 'me' ? 'ring-primary ring-1' : ''}
/>
profile ? (
<Avatar className={cn('w-7 h-7', current === 'me' ? 'ring-primary ring-1' : '')}>
<AvatarImage src={profile.avatar} className="object-cover object-center" />
<AvatarFallback>
<img src={defaultAvatar} />
</AvatarFallback>
</Avatar>
) : (
<Skeleton
className={cn('w-7 h-7 rounded-full', current === 'me' ? 'ring-primary ring-1' : '')}
/>
)
) : (
<UserRound />
)}