Skip to content

#95 When the screen is resized, second level selection moves #90

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

Open
wants to merge 1 commit into
base: nav-bugbash-2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/components/TopNav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ const TopNav = ({
let found = { m1: null, m2: null, m3: null }

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

menuWithId_.forEach(level1 => {
if (level1.href && path_.indexOf(level1.href) > -1) found = { m1: level1.id, m2: null }
Expand All @@ -357,21 +357,32 @@ const TopNav = ({
} else {
found = { m1: level1.id, m2: level2.id, m3: level3.id }
}
if(!activeLevel3Id && level3.collapsed) setforceHideLevel3(true)
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;
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
if (path_.indexOf(href) > -1) found = { m1: level1.id, m3: level3.id }
}
})
})
return found
}

useEffect(() => {
// when scren change size, keep green indicator keep static
const onResize = _.debounce(() => {
const { m3 } = getMenuIdsFromPath(menuWithId, path)
setIconSelectPos(m3)
}, 30)

window.addEventListener('resize', onResize)
return () => window.removeEventListener('resize', onResize)
}, [getMenuIdsFromPath])

useEffect(() => {
if (!path || !menuWithId[0]) return
setLeftNav(menuWithId)
Expand All @@ -390,13 +401,13 @@ const TopNav = ({
forceExpand = true
forceM2 = getMenuIdsFromPath(menuWithId, '/challenges').m2
}
} else if (path.indexOf('/my-dashboard') > -1 || path.indexOf('/members/'+profileHandle) > -1) {
} else if (path.indexOf('/my-dashboard') > -1 || path.indexOf('/members/' + profileHandle) > -1) {
// If My Dashboard and My Profile page
setShowLevel3(true)
} else if (path.indexOf('/community/learn') > -1 || path.indexOf('/thrive/tracks') > -1) {
// Show 3rd level menu to Community [ Overview - How It Works ]
forceM2 = getMenuIdsFromPath(menuWithId, '/community').m2;
} else if(!m2) {
forceM2 = getMenuIdsFromPath(menuWithId, '/community').m2
} else if (!m2) {
setShowLevel3(false)
setforceHideLevel3(true)
}
Expand Down