|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Link from "next/link"; |
| 4 | +import { usePathname } from "next/navigation"; |
| 5 | +import { signIn } from "next-auth/react"; |
| 6 | +import { type Session } from "next-auth"; |
| 7 | +import { useShellActions } from "@/components/Create/ShellActionsProvider"; |
| 8 | + |
| 9 | +/** |
| 10 | + * Bottom nav for small screens (≤720px), where the top-bar nav is absent and |
| 11 | + * the left rail is hidden. Keeps the primary destinations + Create reachable on |
| 12 | + * mobile. Shown via the `.app-mobilenav` media query in globals.css. |
| 13 | + */ |
| 14 | +export function MobileNav({ |
| 15 | + session, |
| 16 | + username, |
| 17 | +}: { |
| 18 | + session: Session | null; |
| 19 | + username: string | null; |
| 20 | +}) { |
| 21 | + const pathname = usePathname(); |
| 22 | + const { openCompose } = useShellActions(); |
| 23 | + |
| 24 | + const items = session |
| 25 | + ? [ |
| 26 | + { name: "Home", href: "/feed" }, |
| 27 | + { name: "Discuss", href: "/discussions" }, |
| 28 | + { name: "Jobs", href: "/jobs" }, |
| 29 | + { name: "Alerts", href: "/notifications" }, |
| 30 | + { name: "You", href: `/${username || "settings"}` }, |
| 31 | + ] |
| 32 | + : [ |
| 33 | + { name: "Home", href: "/feed" }, |
| 34 | + { name: "Discuss", href: "/discussions" }, |
| 35 | + { name: "Jobs", href: "/jobs" }, |
| 36 | + ]; |
| 37 | + |
| 38 | + const isActive = (href: string) => |
| 39 | + href === "/feed" |
| 40 | + ? pathname === "/feed" || pathname === "/" |
| 41 | + : pathname?.startsWith(href); |
| 42 | + |
| 43 | + return ( |
| 44 | + <nav className="app-mobilenav" aria-label="Primary"> |
| 45 | + {items.map((item) => ( |
| 46 | + <Link |
| 47 | + key={item.name} |
| 48 | + href={item.href} |
| 49 | + aria-current={isActive(item.href) ? "page" : undefined} |
| 50 | + className={`flex flex-1 items-center justify-center py-2 text-xs font-medium transition-colors ${ |
| 51 | + isActive(item.href) ? "text-fg" : "text-muted" |
| 52 | + }`} |
| 53 | + > |
| 54 | + {item.name} |
| 55 | + </Link> |
| 56 | + ))} |
| 57 | + {session ? ( |
| 58 | + <button |
| 59 | + onClick={() => openCompose("discussion")} |
| 60 | + aria-label="Create a post" |
| 61 | + className="flex flex-1 items-center justify-center py-2 text-xs font-semibold text-accent" |
| 62 | + > |
| 63 | + + Create |
| 64 | + </button> |
| 65 | + ) : ( |
| 66 | + <button |
| 67 | + onClick={() => signIn()} |
| 68 | + className="flex flex-1 items-center justify-center py-2 text-xs font-semibold text-accent" |
| 69 | + > |
| 70 | + Join |
| 71 | + </button> |
| 72 | + )} |
| 73 | + </nav> |
| 74 | + ); |
| 75 | +} |
0 commit comments