Skip to content

Commit

Permalink
[Navigation bar] Fix active path
Browse files Browse the repository at this point in the history
  • Loading branch information
rikurauhala committed Dec 2, 2024
1 parent e1ee00a commit 8246818
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const NavigationBar = () => {
const { fullAccessToStudentData, isAdmin, isLoading, programmeRights, roles, iamGroups } = useGetAuthorizedUserQuery()
const fullStudyProgrammeRights = getFullStudyProgrammeRights(programmeRights)

const [activeTab, setActiveTab] = useState<number | null>(null)
const [activeTab, setActiveTab] = useState<number | false>(false)

const isActivePath = (mainPath: string | undefined, subPaths: (string | undefined)[] = []) => {
const allPaths = [mainPath, ...subPaths].filter(Boolean)
return allPaths.some(currentPath => location.pathname.includes(currentPath!))
return allPaths.some(currentPath => location.pathname === currentPath)
}

const getVisibleNavigationItems = () => {
Expand Down Expand Up @@ -72,12 +72,8 @@ export const NavigationBar = () => {
return isActivePath(item.path, subItemPaths)
})

if (activeTabIndex >= 0) {
setActiveTab(activeTabIndex)
} else {
setActiveTab(null)
}
}, [location.pathname])
setActiveTab(activeTabIndex >= 0 ? activeTabIndex : false)
}, [location.pathname, visibleNavigationItems])

return (
<AppBar position="static">
Expand Down

0 comments on commit 8246818

Please sign in to comment.