Skip to content

Commit

Permalink
Fix sub-navigation in Staking page
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsmiarowski committed Jun 12, 2023
1 parent 75af025 commit 4cefd91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/components/SubNavigationPills/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,33 @@ const renderPill = (pill: NavPill) => <NavPill key={pill.path} {...pill} />
*/
const addActiveStatusToPills = (pills: RouteProps[]) => {
const pillsWithActiveStatus: NavPill[] = []
let indexOfLastActivePill
const lastActivePill: {
index: number | undefined
pathnameBase: string
} = {
index: undefined,
pathnameBase: "",
}
for (let i = 0; i < pills.length; i++) {
const { path, pathOverride } = pills[i]
const resolved = useResolvedPath(pathOverride || path)
const match = useMatch({ path: resolved.pathname, end: true })
const isActive = !!match
// The second condition here checks if the current match pathnameBase
// includes the pathnameBase of the last active pill. If it does, then this
// pill will be active and we will remove the active status from the
// previous pill. This means that if we have multiple paths that start with
// the same page, such as "staking/how-it-works" and "staking", the active
// one will be the one that useMatch returns true for and has the longest
// pathnameBase (so in this case it will be `staking/how-it-works`).
const isActive =
!!match && match.pathnameBase.includes(lastActivePill.pathnameBase)
if (isActive) {
// remove the active status of the previous pill
if (indexOfLastActivePill !== undefined) {
pillsWithActiveStatus[indexOfLastActivePill].isActive = false
// Remove the active status of the previous pill
if (lastActivePill.index !== undefined) {
pillsWithActiveStatus[lastActivePill.index].isActive = false
}
indexOfLastActivePill = i
lastActivePill.index = i
lastActivePill.pathnameBase = match.pathnameBase
}
const pillWithActiveStatus = {
...pills[i],
Expand Down
1 change: 1 addition & 0 deletions src/pages/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Auth.route = {
StakingPage.route = {
path: "",
index: false,
pathOverride: "*",
title: "Staking",
isPageEnabled: true,
}
Expand Down

0 comments on commit 4cefd91

Please sign in to comment.