- Privacy Policy (with cookies and storage) and Terms of Service, from what the code actually stores and loads; shared LegalText layout - Data requests: a 'privacy' feedback type sent from the Privacy page's form, email required, triaged in Admin -> Feedback - Migration 039: Panel -> Site settings -> Privacy contact email (over site.json's privacyEmail), shown on the Privacy page - The hero livestream, the hero featured video and schedule maps load only when pressed, so no third party sets anything before a click - A small dismissible privacy notice instead of a consent banner Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
351 lines
12 KiB
TypeScript
351 lines
12 KiB
TypeScript
import { useState, useEffect, useRef } from "react";
|
||
import { NavLink, Link, Outlet, useLocation } from "react-router-dom";
|
||
import { PAGE_LINKS, PAGE_SECTIONS, NAV_ACTIONS } from "../navConfig.ts";
|
||
import Banner from "./Banner.tsx";
|
||
import nguLogo from "../assets/logos/NGU_Logo.svg";
|
||
import Footer from "./Footer.tsx";
|
||
import PrivacyNotice from "./PrivacyNotice.tsx";
|
||
|
||
/* ── Right-side nav actions ──────────────────────────────── */
|
||
|
||
type NavActionItem = {
|
||
label: string;
|
||
to: string;
|
||
variant: string;
|
||
external?: boolean;
|
||
};
|
||
|
||
const ACTION_VARIANTS: Record<
|
||
string,
|
||
{ className: string; style: React.CSSProperties }
|
||
> = {
|
||
ghost: {
|
||
className:
|
||
"font-semibold border border-white/30 text-white/85 hover:border-white/60 hover:text-white hover:bg-white/10",
|
||
style: {},
|
||
},
|
||
fancy: {
|
||
className: "font-bold text-white hover:scale-105",
|
||
style: { background: "#0f7183" },
|
||
},
|
||
};
|
||
|
||
const ACTION_SIZES = {
|
||
desktop: "px-5 py-2 text-sm leading-relaxed",
|
||
mobile: "px-8 py-3 text-lg",
|
||
};
|
||
|
||
function NavAction({
|
||
item,
|
||
size = "desktop",
|
||
onClick,
|
||
}: {
|
||
item: NavActionItem;
|
||
size?: keyof typeof ACTION_SIZES;
|
||
onClick?: () => void;
|
||
}) {
|
||
const v = ACTION_VARIANTS[item.variant] ?? ACTION_VARIANTS.ghost;
|
||
const className = `inline-block whitespace-nowrap rounded-full transition-all duration-200 ${ACTION_SIZES[size]} ${v.className}`;
|
||
|
||
return item.external ? (
|
||
<a
|
||
href={item.to}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className={className}
|
||
style={v.style}
|
||
onClick={onClick}
|
||
>
|
||
{item.label}
|
||
</a>
|
||
) : (
|
||
<Link to={item.to} className={className} style={v.style} onClick={onClick}>
|
||
{item.label}
|
||
</Link>
|
||
);
|
||
}
|
||
|
||
const navActions = NAV_ACTIONS as NavActionItem[];
|
||
|
||
/* ── Layout ──────────────────────────────────────────────── */
|
||
|
||
export default function Layout() {
|
||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
||
const [activeSection, setActiveSection] = useState<string | null>(null);
|
||
const [headerHeight, setHeaderHeight] = useState(72);
|
||
const headerRef = useRef<HTMLElement>(null);
|
||
const closeMenuRef = useRef<HTMLButtonElement>(null);
|
||
const location = useLocation();
|
||
|
||
const sections = PAGE_SECTIONS[location.pathname] ?? [];
|
||
const activePage = PAGE_LINKS.find((p) => p.path === location.pathname);
|
||
|
||
// Close the mobile menu whenever the route changes
|
||
useEffect(() => {
|
||
setMobileMenuOpen(false);
|
||
setActiveSection(null);
|
||
}, [location.pathname]);
|
||
|
||
// The open menu is modal: focus starts on its close button, Escape
|
||
// shuts it, and everything behind it is inert (below).
|
||
useEffect(() => {
|
||
if (!mobileMenuOpen) return;
|
||
closeMenuRef.current?.focus();
|
||
const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMobileMenuOpen(false);
|
||
window.addEventListener("keydown", onKey);
|
||
return () => window.removeEventListener("keydown", onKey);
|
||
}, [mobileMenuOpen]);
|
||
|
||
// The header grows and shrinks: the banner can be dismissed and the
|
||
// subnav only exists on some pages. Measure it instead of guessing,
|
||
// so the spacer below always matches.
|
||
useEffect(() => {
|
||
const el = headerRef.current;
|
||
if (!el) return;
|
||
|
||
const ro = new ResizeObserver(([entry]) =>
|
||
setHeaderHeight(entry.contentRect.height)
|
||
);
|
||
ro.observe(el);
|
||
return () => ro.disconnect();
|
||
}, []);
|
||
|
||
// Router does not scroll on navigation. Go to top on a new page,
|
||
// or to the anchor if the URL carries one (handles deep links too).
|
||
useEffect(() => {
|
||
if (location.hash) {
|
||
const el = document.querySelector(location.hash);
|
||
if (el) {
|
||
el.scrollIntoView({ behavior: "smooth" });
|
||
return;
|
||
}
|
||
}
|
||
window.scrollTo({ top: 0 });
|
||
}, [location.pathname, location.hash, location.key]);
|
||
|
||
// Highlight whichever section is currently in view
|
||
useEffect(() => {
|
||
if (sections.length === 0) return;
|
||
|
||
const targets = sections
|
||
.map((s) => document.querySelector(s.hash))
|
||
.filter(Boolean);
|
||
if (targets.length === 0) return;
|
||
|
||
const observer = new IntersectionObserver(
|
||
(entries) => {
|
||
const visible = entries
|
||
.filter((e) => e.isIntersecting)
|
||
.sort(
|
||
(a, b) => a.boundingClientRect.top - b.boundingClientRect.top
|
||
)[0];
|
||
if (visible) setActiveSection(`#${visible.target.id}`);
|
||
},
|
||
// Top margin tracks the live header height so the highlight stays
|
||
// accurate whether or not the banner is showing.
|
||
{ rootMargin: `-${headerHeight + 30}px 0px -60% 0px`, threshold: 0 }
|
||
);
|
||
|
||
targets.forEach((t) => observer.observe(t));
|
||
return () => observer.disconnect();
|
||
}, [location.pathname, headerHeight]);
|
||
|
||
return (
|
||
<div className="min-h-screen overflow-x-hidden">
|
||
<a
|
||
href="#main"
|
||
className="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-[70] focus:rounded-full focus:bg-white focus:px-4 focus:py-2 focus:font-semibold focus:text-[#073d4a]"
|
||
>
|
||
Skip to content
|
||
</a>
|
||
|
||
{/* ── NAV ─────────────────────────────────────────────── */}
|
||
<header
|
||
ref={headerRef}
|
||
className="fixed top-0 left-0 right-0 z-50 backdrop-blur-md"
|
||
inert={mobileMenuOpen}
|
||
>
|
||
|
||
{/* Tier 0, site-wide announcement */}
|
||
<Banner />
|
||
|
||
{/* Tier 1, site navigation */}
|
||
<nav
|
||
className="flex items-center justify-between px-6 py-4"
|
||
aria-label="Site"
|
||
style={{ background: "rgba(0, 69, 82,0.92)" }}
|
||
>
|
||
<div className="flex items-center gap-8">
|
||
<Link to="/" aria-label="Next Generation of Unity home" className="inline-block">
|
||
<img src={nguLogo} alt="Next Generation of Unity" className="h-10 w-auto" />
|
||
</Link>
|
||
|
||
<div className="hidden md:flex items-center gap-6">
|
||
{PAGE_LINKS.map((page) => (
|
||
<NavLink
|
||
key={page.path}
|
||
to={page.path}
|
||
end={page.path === "/"}
|
||
className={({ isActive }) =>
|
||
`text-base font-bold pb-1 border-b-2 transition-colors duration-200 ${
|
||
isActive
|
||
? "text-white border-[#aac992]"
|
||
: "text-white/75 hover:text-white border-transparent"
|
||
}`
|
||
}
|
||
>
|
||
{page.label}
|
||
</NavLink>
|
||
))}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex items-center gap-4">
|
||
<div className="hidden md:flex items-center gap-3">
|
||
{navActions.map((item) => (
|
||
<NavAction key={item.label} item={item} />
|
||
))}
|
||
</div>
|
||
|
||
<button
|
||
className="md:hidden text-white p-2"
|
||
aria-label="Open menu"
|
||
aria-expanded={mobileMenuOpen}
|
||
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
|
||
>
|
||
<div className="w-6 h-0.5 bg-white mb-1.5 transition-all" />
|
||
<div className="w-6 h-0.5 bg-white mb-1.5" />
|
||
<div className="w-6 h-0.5 bg-white" />
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
|
||
{/* Tier 2, sections of the current page */}
|
||
{sections.length > 0 && (
|
||
<nav
|
||
className="hidden md:flex items-center px-6 py-2"
|
||
aria-label={`On this page: ${activePage?.label}`}
|
||
style={{
|
||
background: "rgba(0, 47, 57, 0.92)",
|
||
borderBottom: "1px solid rgba(45,200,224,0.15)",
|
||
}}
|
||
>
|
||
<span className="text-xs text-white/65">{activePage?.label}</span>
|
||
|
||
{/* Separates the page label from its sections */}
|
||
<span
|
||
aria-hidden
|
||
className="mx-5 h-4 w-px"
|
||
style={{ background: "rgba(45,200,224,0.3)" }}
|
||
/>
|
||
|
||
<div className="flex items-center gap-6">
|
||
{sections.map((section) => (
|
||
<a
|
||
key={section.hash}
|
||
href={section.hash}
|
||
aria-current={activeSection === section.hash ? "location" : undefined}
|
||
className={`text-sm transition-colors duration-200 ${
|
||
activeSection === section.hash
|
||
? "text-[#aac992]"
|
||
: "text-white/75 hover:text-[#aac992]"
|
||
}`}
|
||
>
|
||
{section.label}
|
||
</a>
|
||
))}
|
||
</div>
|
||
</nav>
|
||
)}
|
||
</header>
|
||
|
||
{/* Keeps page content clear of the fixed header */}
|
||
<div aria-hidden style={{ height: headerHeight }} />
|
||
|
||
{/* Page content */}
|
||
<main id="main" tabIndex={-1} className="outline-none" inert={mobileMenuOpen}>
|
||
<Outlet />
|
||
</main>
|
||
|
||
{/*Site Footer applied to every page*/}
|
||
<div inert={mobileMenuOpen}>
|
||
<Footer />
|
||
<PrivacyNotice />
|
||
</div>
|
||
|
||
{/* Mobile menu */}
|
||
{mobileMenuOpen && (
|
||
<div
|
||
className="fixed inset-0 z-[60] flex flex-col items-center justify-center overflow-y-auto py-16"
|
||
style={{ background: "rgba(7,61,74,0.97)" }}
|
||
role="dialog"
|
||
aria-modal="true"
|
||
aria-label="Menu"
|
||
>
|
||
<button
|
||
ref={closeMenuRef}
|
||
className="absolute top-5 right-6 text-white text-3xl"
|
||
aria-label="Close menu"
|
||
onClick={() => setMobileMenuOpen(false)}
|
||
>
|
||
×
|
||
</button>
|
||
|
||
<div className="w-64">
|
||
{PAGE_LINKS.map((page) => {
|
||
const pageSections = PAGE_SECTIONS[page.path] ?? [];
|
||
const isActive = location.pathname === page.path;
|
||
|
||
return (
|
||
<div key={page.path}>
|
||
<NavLink
|
||
to={page.path}
|
||
end={page.path === "/"}
|
||
className={({ isActive }) =>
|
||
`block text-2xl font-bold py-3 transition-colors ${
|
||
isActive ? "text-[#aac992]" : "text-white hover:text-[#10d48a]"
|
||
}`
|
||
}
|
||
>
|
||
{page.label}
|
||
</NavLink>
|
||
|
||
{/* Sections nest under the page they belong to */}
|
||
{isActive && pageSections.length > 0 && (
|
||
<div
|
||
className="ml-3 pl-4 mb-2 flex flex-col"
|
||
style={{ borderLeft: "1px solid rgba(45,200,224,0.35)" }}
|
||
>
|
||
{pageSections.map((section) => (
|
||
<a
|
||
key={section.hash}
|
||
href={section.hash}
|
||
className="text-white/80 text-lg py-2 hover:text-[#10d48a] transition-colors"
|
||
onClick={() => setMobileMenuOpen(false)}
|
||
>
|
||
{section.label}
|
||
</a>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
|
||
<div className="mt-8 flex flex-col items-center gap-3">
|
||
{navActions.map((item) => (
|
||
<NavAction
|
||
key={item.label}
|
||
item={item}
|
||
size="mobile"
|
||
onClick={() => setMobileMenuOpen(false)}
|
||
/>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
</div>
|
||
);
|
||
}
|