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