Skip to content

Commit

Permalink
'Requested Changes Done'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivinayakg committed Aug 22, 2022
1 parent 3e19883 commit f82eed7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const Sidebar = () => {
const router = useRouter();
const navigateTo = (url) => router.push(url);

const basePath = router.pathname;
const pagePath = router.pathname.split('/')[1];

const activeOptionClass = (optionURL) =>
pagePath === optionURL || (basePath === '/' && '/' === optionURL)
? ' ' + styles.option_active
: '';

return (
<div className={styles.wrapper} data-testid="sidebar-notification">
<aside className={styles.sidebar}>
Expand All @@ -16,19 +24,14 @@ const Sidebar = () => {
</span>
<div className={styles.options}>
{sidebarMenuOptions.map((option, index) => {
const optionPath = option.urlPath;
return (
<span
key={index}
// this code below insure even if we are in nested path like currency-exchange/**/
//even then the link is active
className={
styles.option +
(router.pathname.split('/')[1] === option.urlPath ||
(router.pathname === '/' && '/' === option.urlPath)
? ' ' + styles.option_active
: '')
}
onClick={() => navigateTo(option.urlPath)}
className={styles.option + activeOptionClass(optionPath)}
onClick={() => navigateTo(optionPath)}
>
<Image
src={option.iconPath}
Expand Down

0 comments on commit f82eed7

Please sign in to comment.