From 4884678f144fc37c532812e3c89470fad4dc1c5f Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Wed, 17 Jun 2026 13:51:18 -0500 Subject: [PATCH] Add active nav links --- src/components/NavLinks.tsx | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/components/NavLinks.tsx diff --git a/src/components/NavLinks.tsx b/src/components/NavLinks.tsx new file mode 100644 index 0000000..e008e69 --- /dev/null +++ b/src/components/NavLinks.tsx @@ -0,0 +1,52 @@ +"use client"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import LogoutButton from "./LogoutButton"; + +export default function NavLinks({ + user, +}: { + user: { username: string; isAdmin: boolean } | null; +}) { + const pathname = usePathname() || "/"; + + const isActive = (href: string) => + href === "/" ? pathname === "/" : pathname === href || pathname.startsWith(href + "/"); + + const cls = (href: string, extra = "") => { + const parts = [extra, isActive(href) ? "active" : ""].filter(Boolean); + return parts.join(" ") || undefined; + }; + const current = (href: string) => (isActive(href) ? "page" : undefined); + + return ( +
+ + Learn + + {user ? ( + <> + {user.isAdmin && ( + + Admin + + )} + + Report a problem + + {user.username} + + + ) : ( + <> + + Log in + + + Sign up + + + )} +
+ ); +}