Skip to content

Commit 448cc8d

Browse files
Merge pull request topcoder-platform#144 from gets0ul/community-app_issue_3440
Fix for community-app issue topcoder-platform#148
2 parents ec65a86 + dc7bbd0 commit 448cc8d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/components/TopNav/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,46 @@ const TopNav = ({
249249
}
250250
}, [activeLevel1Id, activeLevel2Id, path])
251251

252+
const isLevel3ExactPath = (menuWithId_, path_) => {
253+
let found = { exact: false }
254+
255+
// If haven't a path just return
256+
if (!path_) return found
257+
258+
menuWithId_.forEach(level1 => {
259+
level1.subMenu && level1.subMenu.forEach(level2 => {
260+
level2.subMenu && level2.subMenu.forEach(level3 => {
261+
if (level3.href && path_.indexOf(level3.href) > -1) {
262+
if (found.exact) {
263+
if (level3.href === path_) found = { exact: true }
264+
} else {
265+
found = { exact: path_.endsWith(level3.href) }
266+
}
267+
}
268+
})
269+
})
270+
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
271+
if (level3.href) {
272+
// Check if path have parameters
273+
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
274+
if (path_.indexOf(href) > -1) found = { exact: path_.endsWith(href) }
275+
}
276+
})
277+
})
278+
return found
279+
}
280+
281+
useEffect(() => {
282+
if (!path || !menuWithId) return
283+
// check if current path is an exact matches with level3 href
284+
const { exact } = isLevel3ExactPath(menuWithId, path)
285+
if (!exact) {
286+
setActiveLevel3Id(undefined)
287+
setIconSelectPos(undefined)
288+
setShowIconSelect(false)
289+
}
290+
}, [activeLevel3Id])
291+
252292
const createHandleClickLevel3 = menuId => () => {
253293
setActiveLevel3Id(menuId)
254294
setIconSelectPos(menuId)

0 commit comments

Comments
 (0)