Skip to content

Commit 0694e6f

Browse files
#170: Ability to navigate back to THRIVE homepage from an article
1 parent aee3a27 commit 0694e6f

File tree

5 files changed

+19
-44
lines changed

5 files changed

+19
-44
lines changed

dist/dev/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/prod/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/TopNav/SubNav.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const SubNav = ({
1212
isSecondaryMenu,
1313
isResize,
1414
activeChildId,
15+
exact,
1516
showIndicator,
1617
indicatorX,
1718
createHandleClickItem,
@@ -23,7 +24,11 @@ const SubNav = ({
2324
const to = _.isEmpty(level3.link) ? level3.href : level3.link
2425
return (
2526
<Link
26-
className={cn(styles.secondaryNavItem, level3.id === activeChildId && styles.secondaryNavItemOpen)}
27+
className={cn(
28+
styles.secondaryNavItem,
29+
level3.id === activeChildId && styles.secondaryNavItemOpen,
30+
(level3.id === activeChildId && exact) && styles.secondaryNavItemActive
31+
)}
2732
key={`level3-${i}`}
2833
to={to}
2934
onClick={!level3.openNewTab && createHandleClickItem(level3.id)}
@@ -44,6 +49,7 @@ SubNav.propTypes = {
4449
isResize: PropTypes.bool,
4550
isSecondaryMenu: PropTypes.bool,
4651
activeChildId: PropTypes.any,
52+
exact: PropTypes.bool,
4753
showIndicator: PropTypes.bool,
4854
indicatorX: PropTypes.number,
4955
createHandleClickItem: PropTypes.func,

src/components/TopNav/SubNav.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
}
7171
&.secondaryNavItemOpen {
7272
@include Roboto-Bold;
73+
}
74+
&.secondaryNavItemActive {
7375
@include not-clickable;
7476
}
7577
}

src/components/TopNav/index.js

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const TopNav = ({
9090
const [activeLevel1Id, setActiveLevel1Id] = useState()
9191
const [activeLevel2Id, setActiveLevel2Id] = useState()
9292
const [activeLevel3Id, setActiveLevel3Id] = useState()
93+
const [level3Exact, setLevel3Exact] = useState(false)
9394
const [isResize, setResize] = useState(false)
9495
const [showLevel3, setShowLevel3] = useState(false)
9596
const [forceHideLevel3, setforceHideLevel3] = useState(false)
@@ -249,42 +250,6 @@ const TopNav = ({
249250
}
250251
}, [activeLevel1Id, activeLevel2Id, path])
251252

252-
const isLevel3ExactPath = (menuWithId_, path_) => {
253-
let exact = false
254-
255-
// If haven't a path just return
256-
if (!path_) return exact
257-
258-
menuWithId_.forEach(level1 => {
259-
level1.subMenu && level1.subMenu.forEach(level2 => {
260-
level2.subMenu && level2.subMenu.forEach(level3 => {
261-
if (level3.href && level3.href === path_) {
262-
exact = true
263-
return exact
264-
}
265-
})
266-
})
267-
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
268-
if (level3.href && level3.href === path_) {
269-
exact = true
270-
return exact
271-
}
272-
})
273-
})
274-
return exact
275-
}
276-
277-
useEffect(() => {
278-
if (!path || !menuWithId) return
279-
// check if current path is an exact matches with level3 href
280-
const exact = isLevel3ExactPath(menuWithId, path)
281-
if (!exact) {
282-
setActiveLevel3Id(undefined)
283-
setIconSelectPos(undefined)
284-
setShowIconSelect(false)
285-
}
286-
}, [activeLevel3Id])
287-
288253
const createHandleClickLevel3 = menuId => () => {
289254
setActiveLevel3Id(menuId)
290255
setIconSelectPos(menuId)
@@ -441,9 +406,10 @@ const TopNav = ({
441406
if (level2.href && path_.indexOf(level2.href) > -1) found = { m1: level1.id, m2: level2.id }
442407
level2.subMenu && level2.subMenu.forEach(level3 => {
443408
if (level3.href && path_.indexOf(level3.href) > -1) {
444-
if (found.m3) {
445-
if (level3.href === path_) found = { m1: level1.id, m2: level2.id, m3: level3.id }
446-
} else {
409+
if (level3.href && level3.href === path_) {
410+
found = { m1: level1.id, m2: level2.id, m3: level3.id }
411+
setLevel3Exact(true)
412+
} else if (!found.m3) {
447413
found = { m1: level1.id, m2: level2.id, m3: level3.id }
448414
}
449415
if (!activeLevel3Id && level3.collapsed) setforceHideLevel3(true)
@@ -572,6 +538,7 @@ const TopNav = ({
572538
isResize={isResize}
573539
isSecondaryMenu={!activeMenu2}
574540
activeChildId={activeLevel3Id}
541+
exact={level3Exact}
575542
showIndicator={showIconSelect}
576543
indicatorX={iconSelectX}
577544
createHandleClickItem={createHandleClickLevel3}

0 commit comments

Comments
 (0)