perf: nav bar avatar
This commit is contained in:
@@ -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 />
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user