-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnav-bar.tsx
More file actions
77 lines (65 loc) · 2.01 KB
/
nav-bar.tsx
File metadata and controls
77 lines (65 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { MdOutlineBookmark } from "react-icons/md/index"
import * as Dailp from "src/graphql/dailp"
import { useLocation } from "src/renderer/PageShell"
import { DropdownNavItem } from "./dropdown-nav-item"
import { navBar, navIcons, navLinks } from "./nav-bar.css"
export const NavBar = () => {
const location = useLocation()
const [{ data, fetching, error }] = Dailp.useMenuBySlugQuery({
variables: { slug: "default-nav" },
})
if (fetching) return null
if (error) return null
const menuItems = data?.menuBySlug?.items
if (!menuItems) return null
// Handles top-level nav items
const isTopLevel = (a: any) =>
!menuItems.some((b: any) => b?.items?.some((c: any) => c?.path === a?.path))
return (
<nav className={navBar}>
<ul className={navLinks}>
{menuItems.filter(isTopLevel).map((item: any) => {
if (!item) return null
// Handles dropdown nav items
if (item.items?.length) {
return (
<DropdownNavItem
key={item.label}
label={item.label}
links={item.items.map((child: any) => ({
text: child.label,
href: child.path,
}))}
/>
)
}
// Normal link
let href = item.path
if (item.path?.startsWith("http")) {
href = new URL(item.path).pathname
}
return (
<li key={item.path}>
<a
href={href}
aria-current={location.pathname === href ? "page" : undefined}
>
{item.label}
</a>
</li>
)
})}
<li className={navIcons}>
{/* Only show for logged in users, otherwise "Log in" */}
<i className="fa-solid fa-user"></i>
<i className="fa-solid fa-gear"></i>
<i className="fa-solid fa-bell"></i>
</li>
</ul>
</nav>
)
}
{
/* ADD MOBILE NAV BAR */
}
export default NavBar