-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
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.
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
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.
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`.
@r-czajkowski It should be fixed now in 780e859 |
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
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.
b6cd43b
to
3113a7e
Compare
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
cc96c36
to
dee2428
Compare
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
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.
Preview uploaded to https://preview.dashboard.test.threshold.network/subnav-pills-fix/index.html. |
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 bothBridge
andHow it works
links were active.We've fixed that by adding a new method -
addActiveStatusToPills
- which addsisActive
property to each of the link. If there are two or more links that are active (based onuseMatch
hook) then we only keep the active status for the last one.Additionally I've also fixed the sub-navigation for
Staking
page because theStaking
pill was not active when being on authorization page.Screenshot of the fix