Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two active navigation pills #524

Merged
merged 9 commits into from
Aug 16, 2023
Merged

Fix two active navigation pills #524

merged 9 commits into from
Aug 16, 2023

Conversation

michalsmiarowski
Copy link
Contributor

@michalsmiarowski michalsmiarowski commented May 26, 2023

Closes: #501

There was a UI bug where it displayed two navigation pills as active instead of one. For example when clicking on How it works link in tbtc both Bridge and How it works links were active.

We've fixed that by adding a new method - addActiveStatusToPills - which adds isActive property to each of the link. If there are two or more links that are active (based on useMatch hook) then we only keep the active status for the last one.

Additionally I've also fixed the sub-navigation for Staking page because the Staking pill was not active when being on authorization page.

Screenshot of the fix image image

There was a UI bug where it displayed two navigation pills as active instead of
one. For example when clicking on `How it works` link in tbtc both `Bridge` and
`How it works` links were active.

We've fixed that by adding a new method - `addActiveStatusToPills` - which adds
`isActive` property to each of the link. If there are two or more links that are
active (based on `useMatch` hook) then we only keep the active status for the
last one.
@michalsmiarowski michalsmiarowski marked this pull request as ready for review May 26, 2023 08:39
@github-actions
Copy link

@github-actions
Copy link

The previous fix used hooks inside loops which should not be done (see
https://legacy.reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level).

As a workaround I decided to refactor the fix. Now we gather all resolved paths
for all the pills that are in the menu using `resolvePath` function and we pass
those paths to each pill component. Inside the component we check if `useMatch`
hook returns anything for the given pill and if yes then we check if is is
because it has asterisk (`*`) in it's path. If yes, then we first have to check
if the url match any of the other pills using our array of resolved paths. If
not then we can safely assume that this pill can be active.
We are not inside any loop so we can safely use `useMatch` hook.
@github-actions
Copy link

@r-czajkowski r-czajkowski self-requested a review July 17, 2023 10:57
Copy link
Collaborator

@r-czajkowski r-czajkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it doesn't work on Staking How it works page.

obraz

I've manage to resolve the issue using `resolvePath` and `matchPath` functions
instead of `useMatch` and `useResolvedPath` hooks. For that I had to introduce a
new property - `parentPath` - that is passed to `SubNavigationPills` component
and will be used as a `pathnaemBase` for the `resolvePath` function.

If more than one pill is active then the one with the longest `pathnameBase`
from the `matchPath` function will be active. This will happen when there are
two paths with asterisk, for example:
`tBTC/*`,
`tBTC/how-it-work/*`.

For the path `tBTC/how-it-work/overview` we want only the second one to be
active so we are picking the one with the longest `pathnameBase`. In the first
case the pathnameBase is `tBTC` and in the second one it's `tBTC/how-it-works`.
@michalsmiarowski
Copy link
Contributor Author

Looks like it doesn't work on Staking How it works page.

@r-czajkowski It should be fixed now in 780e859

@github-actions
Copy link

@michalsmiarowski michalsmiarowski modified the milestones: v1.9.0, v1.10.0 Jul 25, 2023
@github-actions
Copy link

The navigation did not work in preview links because the branch name was in the
url. This resulted in `window.location.pathname` returning wrong pathname.
@github-actions
Copy link

src/App.tsx Outdated Show resolved Hide resolved
src/App.tsx Outdated Show resolved Hide resolved
src/components/SubNavigationPills/index.tsx Outdated Show resolved Hide resolved
src/types/page.ts Outdated Show resolved Hide resolved
@github-actions
Copy link

@github-actions
Copy link

Having `parentPathBase` in `ParentComponent` type (but not in `RouteProps`)
actually complicated more thing than it resolves. I've decided to put it in
`RouteProps` as an optional parameter. Then we assing the correct
`parentPathBase` to a specific `RouteProps` object inside `renderPageComponent`
function.

This way we don't have to pass `parentPathBase` parameter to all PageComponents
manually all the way to `SubNavigaionPillsProps` because we already have it in
`links` parameter.
@github-actions
Copy link

@r-czajkowski r-czajkowski merged commit c62bddd into main Aug 16, 2023
5 checks passed
@r-czajkowski r-czajkowski deleted the subnav-pills-fix branch August 16, 2023 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two active subnav tabs in minting dapp
2 participants