Skip to content

Commit

Permalink
Merge pull request #171 from topcoder-platform/nav-hotfix-thrive-link
Browse files Browse the repository at this point in the history
Nav hotfix thrive link
  • Loading branch information
sushilshinde authored Apr 15, 2020
2 parents 832e036 + 0694e6f commit 24bd508
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 52 deletions.
6 changes: 3 additions & 3 deletions dist/dev/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/prod/index.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/components/TopNav/SubNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const SubNav = ({
isSecondaryMenu,
isResize,
activeChildId,
exact,
showIndicator,
indicatorX,
createHandleClickItem,
Expand All @@ -23,7 +24,11 @@ const SubNav = ({
const to = _.isEmpty(level3.link) ? level3.href : level3.link
return (
<Link
className={cn(styles.secondaryNavItem, level3.id === activeChildId && styles.secondaryNavItemOpen)}
className={cn(
styles.secondaryNavItem,
level3.id === activeChildId && styles.secondaryNavItemOpen,
(level3.id === activeChildId && exact) && styles.secondaryNavItemActive
)}
key={`level3-${i}`}
to={to}
onClick={!level3.openNewTab && createHandleClickItem(level3.id)}
Expand All @@ -44,6 +49,7 @@ SubNav.propTypes = {
isResize: PropTypes.bool,
isSecondaryMenu: PropTypes.bool,
activeChildId: PropTypes.any,
exact: PropTypes.bool,
showIndicator: PropTypes.bool,
indicatorX: PropTypes.number,
createHandleClickItem: PropTypes.func,
Expand Down
2 changes: 2 additions & 0 deletions src/components/TopNav/SubNav.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
}
&.secondaryNavItemOpen {
@include Roboto-Bold;
}
&.secondaryNavItemActive {
@include not-clickable;
}
}
Expand Down
55 changes: 8 additions & 47 deletions src/components/TopNav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const TopNav = ({
const [activeLevel1Id, setActiveLevel1Id] = useState()
const [activeLevel2Id, setActiveLevel2Id] = useState()
const [activeLevel3Id, setActiveLevel3Id] = useState()
const [level3Exact, setLevel3Exact] = useState(false)
const [isResize, setResize] = useState(false)
const [showLevel3, setShowLevel3] = useState(false)
const [forceHideLevel3, setforceHideLevel3] = useState(false)
Expand Down Expand Up @@ -249,46 +250,6 @@ const TopNav = ({
}
}, [activeLevel1Id, activeLevel2Id, path])

const isLevel3ExactPath = (menuWithId_, path_) => {
let found = { exact: false }

// If haven't a path just return
if (!path_) return found

menuWithId_.forEach(level1 => {
level1.subMenu && level1.subMenu.forEach(level2 => {
level2.subMenu && level2.subMenu.forEach(level3 => {
if (level3.href && path_.indexOf(level3.href) > -1) {
if (found.exact) {
if (level3.href === path_) found = { exact: true }
} else {
found = { exact: path_.endsWith(level3.href) }
}
}
})
})
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
if (level3.href) {
// Check if path have parameters
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
if (path_.indexOf(href) > -1) found = { exact: path_.endsWith(href) }
}
})
})
return found
}

useEffect(() => {
if (!path || !menuWithId) return
// check if current path is an exact matches with level3 href
const { exact } = isLevel3ExactPath(menuWithId, path)
if (!exact) {
setActiveLevel3Id(undefined)
setIconSelectPos(undefined)
setShowIconSelect(false)
}
}, [activeLevel3Id])

const createHandleClickLevel3 = menuId => () => {
setActiveLevel3Id(menuId)
setIconSelectPos(menuId)
Expand Down Expand Up @@ -445,20 +406,19 @@ const TopNav = ({
if (level2.href && path_.indexOf(level2.href) > -1) found = { m1: level1.id, m2: level2.id }
level2.subMenu && level2.subMenu.forEach(level3 => {
if (level3.href && path_.indexOf(level3.href) > -1) {
if (found.m3) {
if (level3.href === path_) found = { m1: level1.id, m2: level2.id, m3: level3.id }
} else {
if (level3.href && level3.href === path_) {
found = { m1: level1.id, m2: level2.id, m3: level3.id }
setLevel3Exact(true)
} else if (!found.m3) {
found = { m1: level1.id, m2: level2.id, m3: level3.id }
}
if (!activeLevel3Id && level3.collapsed) setforceHideLevel3(true)
}
})
})
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
if (level3.href) {
// Check if path have parameters
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
if (path_.indexOf(href) > -1) found = { m1: level1.id, m3: level3.id }
if (level3.href && level3.href === path_) {
found = { m1: level1.id, m3: level3.id }
}
})
})
Expand Down Expand Up @@ -578,6 +538,7 @@ const TopNav = ({
isResize={isResize}
isSecondaryMenu={!activeMenu2}
activeChildId={activeLevel3Id}
exact={level3Exact}
showIndicator={showIconSelect}
indicatorX={iconSelectX}
createHandleClickItem={createHandleClickLevel3}
Expand Down

0 comments on commit 24bd508

Please sign in to comment.