Skip to content

Commit

Permalink
Improve navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
polarker committed Aug 29, 2023
1 parent ebeb8b4 commit 3c55889
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/components/AppNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
IconFileAnalytics,
} from '@tabler/icons-react'
import { LinksGroup } from './AppNavBarLinkGroup'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { useLocation } from 'react-router-dom'

const mockdata = [
{
Expand Down Expand Up @@ -110,7 +111,13 @@ const useStyles = createStyles((theme) => ({

export function NavbarNested() {
const { classes } = useStyles()
const location = useLocation()
const [active, setActive] = useState<string>(mockdata[0].label)

useEffect(() => {
setActive(location.pathname)
}, [location.pathname])

const links = mockdata.map((item) => (
<LinksGroup
{...item}
Expand Down
8 changes: 4 additions & 4 deletions src/components/AppNavBarLinkGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export function LinksGroup({
<Text
component={Link}
className={cx(classes.link, {
[classes.linkActive]: label + link.label === active,
[classes.linkActive]: link.link === active,
})}
to={link.link}
key={link.label}
ta="left"
onClick={() => setActive(label + link.label)}
onClick={() => setActive(link.link)}
>
{link.label}
</Text>
Expand All @@ -123,14 +123,14 @@ export function LinksGroup({
onClick={() => {
setOpened((o) => !o)
if (!hasLinks) {
setActive(label)
setActive(groupLink ?? '')
}
if (groupLink) {
navigate(groupLink)
}
}}
className={cx(classes.control, {
[classes.linkActive]: !hasLinks && label === active,
[classes.linkActive]: !hasLinks && groupLink === active,
})}
>
<Group position="apart" spacing={0}>
Expand Down

0 comments on commit 3c55889

Please sign in to comment.