Skip to content

Commit

Permalink
Merge pull request #1986 from oasisprotocol/lw/subnav-active-route
Browse files Browse the repository at this point in the history
Make Stake button active in delegations and debonding routes
  • Loading branch information
lukaw3d authored Jul 4, 2024
2 parents b91f81d + 378439e commit 4047858
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/1986.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make Stake button active in delegations and debonding routes
19 changes: 15 additions & 4 deletions src/app/components/MobileFooterNavigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const MobileFooterNavigation = ({ walletHasAccounts, isMobile }: MobileFo
label: t('menu.wallet', 'Account'),
Icon: Money,
to: `/account/${address}`,
exactActive: true,
},
{
label: t('menu.stake-mobile', 'Stake'),
Expand Down Expand Up @@ -88,16 +89,26 @@ export const MobileFooterNavigation = ({ walletHasAccounts, isMobile }: MobileFo

return (
<StyledMobileFooterNavigation data-testid="mobile-footer-navigation">
{getMenuItems.map(({ label, Icon, to }) => (
<MobileFooterButton key={to} label={label} Icon={Icon} to={to} />
{getMenuItems.map(params => (
<MobileFooterButton key={params.to} {...params} />
))}
</StyledMobileFooterNavigation>
)
}

function MobileFooterButton({ label, Icon, to }: { label: string; Icon: Icon; to: string }) {
function MobileFooterButton({
label,
Icon,
to,
exactActive,
}: {
label: string
Icon: Icon
to: string
exactActive?: boolean | undefined
}) {
const location = useLocation()
const isActive = to === location.pathname
const isActive = exactActive ? location.pathname === to : location.pathname.startsWith(to)

return (
<StyledNavLink to={to}>
Expand Down
24 changes: 21 additions & 3 deletions src/app/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
mobileToolbarZIndex,
} from '../../../styles/theme/elementSizes'
import { ThemeContext } from 'styled-components'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { MobileFooterNavigation } from '../MobileFooterNavigation'

interface SidebarButtonBaseProps {
needsWalletOpen?: boolean
Expand All @@ -47,9 +49,10 @@ interface SidebarButtonBaseProps {

type SidebarButtonProps = SidebarButtonBaseProps &
(
| { route: string; newTab?: boolean; onClick?: undefined }
| { route: string; exactActive?: boolean; newTab?: boolean; onClick?: undefined }
| {
route?: undefined
exactActive?: undefined
newTab?: undefined
onClick: React.MouseEventHandler<HTMLButtonElement> & React.MouseEventHandler<HTMLAnchorElement>
}
Expand All @@ -61,12 +64,17 @@ export const SidebarButton = ({
label,
route,
newTab,
exactActive,
onClick,
...rest
}: SidebarButtonProps) => {
const walletHasAccounts = useSelector(selectHasAccounts)
const location = useLocation()
const isActive = route ? route === location.pathname : false
const isActive = route
? exactActive
? location.pathname === route
: location.pathname.startsWith(route)
: false

if (!walletHasAccounts && needsWalletOpen) {
return null
Expand Down Expand Up @@ -229,18 +237,28 @@ const SidebarFooter = (props: SidebarFooterProps) => {
)
}

/** See also {@link MobileFooterNavigation} */
function SidebarMenuItems() {
const address = useSelector(selectAddress)
const { t } = useTranslation()
const { getParaTimesRoutePath, paraTimesRouteLabel } = useParaTimesNavigation()
const menu = {
home: <SidebarButton icon={<Home />} label={t('menu.home', 'Home')} route="/" data-testid="nav-home" />,
home: (
<SidebarButton
icon={<Home />}
label={t('menu.home', 'Home')}
route="/"
exactActive
data-testid="nav-home"
/>
),
wallet: (
<SidebarButton
icon={<Money />}
label={t('menu.wallet', 'Account')}
needsWalletOpen={true}
route={`/account/${address}`}
exactActive
data-testid="nav-myaccount"
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function StakeSubnavigation() {
? t('account.subnavigation.mobileActiveDelegations', 'Staked')
: t('account.subnavigation.activeDelegations', 'Staked')
}
route={`/account/${address}/active-delegations`}
route={`/account/${address}/stake/active-delegations`}
/>

<NavItem
Expand All @@ -80,7 +80,7 @@ export function StakeSubnavigation() {
? t('account.subnavigation.mobileDebondingDelegations', 'Debonding')
: t('account.subnavigation.debondingDelegations', 'Debonding')
}
route={`/account/${address}/debonding-delegations`}
route={`/account/${address}/stake/debonding-delegations`}
/>
</Nav>
)
Expand Down
4 changes: 2 additions & 2 deletions src/commonRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const commonRoutes: RouteObject[] = [
element: <ValidatorList />,
},
{
path: 'active-delegations',
path: 'stake/active-delegations',
element: <ActiveDelegationList />,
},
{
path: 'debonding-delegations',
path: 'stake/debonding-delegations',
element: <DebondingDelegationList />,
},
{
Expand Down

0 comments on commit 4047858

Please sign in to comment.