fix: improve active state logic for navigation buttons
This commit is contained in:
@@ -9,32 +9,31 @@ import { useMemo } from 'react'
|
|||||||
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
||||||
|
|
||||||
export default function AccountButton() {
|
export default function AccountButton() {
|
||||||
const { navigate, current } = usePrimaryPage()
|
const { navigate, current, display } = usePrimaryPage()
|
||||||
const { pubkey, profile } = useNostr()
|
const { pubkey, profile } = useNostr()
|
||||||
const defaultAvatar = useMemo(
|
const defaultAvatar = useMemo(
|
||||||
() => (profile?.pubkey ? generateImageByPubkey(profile.pubkey) : ''),
|
() => (profile?.pubkey ? generateImageByPubkey(profile.pubkey) : ''),
|
||||||
[profile]
|
[profile]
|
||||||
)
|
)
|
||||||
|
const active = useMemo(() => current === 'me' && display, [display, current])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigationBarItem
|
<BottomNavigationBarItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate('me')
|
navigate('me')
|
||||||
}}
|
}}
|
||||||
active={current === 'me'}
|
active={active}
|
||||||
>
|
>
|
||||||
{pubkey ? (
|
{pubkey ? (
|
||||||
profile ? (
|
profile ? (
|
||||||
<Avatar className={cn('w-7 h-7', current === 'me' ? 'ring-primary ring-1' : '')}>
|
<Avatar className={cn('w-7 h-7', active ? 'ring-primary ring-1' : '')}>
|
||||||
<AvatarImage src={profile.avatar} className="object-cover object-center" />
|
<AvatarImage src={profile.avatar} className="object-cover object-center" />
|
||||||
<AvatarFallback>
|
<AvatarFallback>
|
||||||
<img src={defaultAvatar} />
|
<img src={defaultAvatar} />
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
) : (
|
) : (
|
||||||
<Skeleton
|
<Skeleton className={cn('w-7 h-7 rounded-full', active ? 'ring-primary ring-1' : '')} />
|
||||||
className={cn('w-7 h-7 rounded-full', current === 'me' ? 'ring-primary ring-1' : '')}
|
|
||||||
/>
|
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<UserRound />
|
<UserRound />
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ import { Compass } from 'lucide-react'
|
|||||||
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
||||||
|
|
||||||
export default function ExploreButton() {
|
export default function ExploreButton() {
|
||||||
const { navigate, current } = usePrimaryPage()
|
const { navigate, current, display } = usePrimaryPage()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigationBarItem active={current === 'explore'} onClick={() => navigate('explore')}>
|
<BottomNavigationBarItem
|
||||||
|
active={current === 'explore' && display}
|
||||||
|
onClick={() => navigate('explore')}
|
||||||
|
>
|
||||||
<Compass />
|
<Compass />
|
||||||
</BottomNavigationBarItem>
|
</BottomNavigationBarItem>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ import { Home } from 'lucide-react'
|
|||||||
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
import BottomNavigationBarItem from './BottomNavigationBarItem'
|
||||||
|
|
||||||
export default function HomeButton() {
|
export default function HomeButton() {
|
||||||
const { navigate, current } = usePrimaryPage()
|
const { navigate, current, display } = usePrimaryPage()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigationBarItem active={current === 'home'} onClick={() => navigate('home')}>
|
<BottomNavigationBarItem
|
||||||
|
active={current === 'home' && display}
|
||||||
|
onClick={() => navigate('home')}
|
||||||
|
>
|
||||||
<Home />
|
<Home />
|
||||||
</BottomNavigationBarItem>
|
</BottomNavigationBarItem>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import BottomNavigationBarItem from './BottomNavigationBarItem'
|
|||||||
|
|
||||||
export default function NotificationsButton() {
|
export default function NotificationsButton() {
|
||||||
const { checkLogin } = useNostr()
|
const { checkLogin } = useNostr()
|
||||||
const { navigate, current } = usePrimaryPage()
|
const { navigate, current, display } = usePrimaryPage()
|
||||||
const { hasNewNotification } = useNotification()
|
const { hasNewNotification } = useNotification()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigationBarItem
|
<BottomNavigationBarItem
|
||||||
active={current === 'notifications'}
|
active={current === 'notifications' && display}
|
||||||
onClick={() => checkLogin(() => navigate('notifications'))}
|
onClick={() => checkLogin(() => navigate('notifications'))}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|||||||
Reference in New Issue
Block a user