1+ import { useQuery } from "@tanstack/react-query" ;
12import { Link } from "@tanstack/react-router" ;
23import { Menu } from "lucide-react" ;
34import { memo , useCallback , useState } from "react" ;
45
56import acmLogo from "@/assets/logos/acm.svg" ;
67import { Button } from "@/components/ui/button" ;
78import { Sheet , SheetContent , SheetHeader , SheetTrigger } from "@/components/ui/sheet" ;
9+ import { meQueryOptions } from "@/routes/dashboard/route" ;
810
911interface NavEntry {
1012 href : string ;
@@ -18,6 +20,9 @@ const NAV_LINKS: NavEntry[] = [
1820 { href : "/projects" , label : "Projects" } ,
1921] ;
2022
23+ const DASHBOARD_ENTRY : NavEntry = { href : "/dashboard" , label : "Dashboard" } ;
24+ const GUEST_ENTRY : NavEntry = { href : "/login" , label : "Login" } ;
25+
2126const NAV_LINK_CLASSES =
2227 "relative cursor-pointer pb-1 text-[15px] font-bold tracking-[0.02em] transition-colors text-brand-text-sub hover:text-foreground data-[status=active]:text-foreground" ;
2328const NAV_LINK_UNDERLINE_CLASSES =
@@ -53,11 +58,16 @@ const SheetNavLink = memo(function SheetNavLink({
5358} ) ;
5459
5560function MobileNav ( ) {
61+ const { data : member } = useQuery ( meQueryOptions ) ;
62+
5663 const [ open , setOpen ] = useState ( false ) ;
64+
5765 const closeSheet = useCallback ( ( ) => {
5866 setOpen ( false ) ;
5967 } , [ ] ) ;
6068
69+ const entries = [ ...NAV_LINKS , member ? DASHBOARD_ENTRY : GUEST_ENTRY ] ;
70+
6171 return (
6272 < Sheet open = { open } onOpenChange = { setOpen } >
6373 < SheetTrigger
@@ -75,7 +85,7 @@ function MobileNav() {
7585 < SheetContent side = "right" className = "w-72 bg-brand-navbar" >
7686 < SheetHeader />
7787 < nav className = "flex flex-col gap-2 px-4" >
78- { NAV_LINKS . map ( ( entry ) => (
88+ { entries . map ( ( entry ) => (
7989 < SheetNavLink key = { entry . href } entry = { entry } onNavigate = { closeSheet } />
8090 ) ) }
8191 </ nav >
@@ -85,6 +95,10 @@ function MobileNav() {
8595}
8696
8797export function Navbar ( ) {
98+ const { data : member } = useQuery ( meQueryOptions ) ;
99+
100+ const entries = [ ...NAV_LINKS , member ? DASHBOARD_ENTRY : GUEST_ENTRY ] ;
101+
88102 return (
89103 < nav className = "sticky top-0 z-50 flex h-16 w-full items-center justify-between bg-brand-navbar px-5 shadow-[0px_10px_30px_rgba(112,144,176,0.2)] md:h-20.5 md:px-14" >
90104 < Link to = "/" className = "flex cursor-pointer items-center gap-2" >
@@ -100,7 +114,7 @@ export function Navbar() {
100114 </ Link >
101115
102116 < div className = "hidden gap-9 md:flex" >
103- { NAV_LINKS . map ( ( entry ) => (
117+ { entries . map ( ( entry ) => (
104118 < DesktopNavLink key = { entry . href } entry = { entry } />
105119 ) ) }
106120 </ div >
0 commit comments