"use client"; // ============================================================================= // CookieBanner // ============================================================================= // // A small, non-blocking cookie / consent banner shown on first visit. // Two buttons: ACK (accept) / RST (reject) — network-engineer humour. // // Behaviour: // - On first load, if no consent decision is stored, the banner appears. // - "ACK" stores `novarix-cookie-consent = "ack"` in localStorage and the // banner closes. // - "RST" stores `novarix-cookie-consent = "rst"` in localStorage and the // banner closes. // - The footer "Cookie preferences" link dispatches a window event that // re-opens this banner so users can change their mind. // // All visible text comes from `/content.ts` -> site.cookies. // ============================================================================= import Link from "next/link"; import { useEffect, useLayoutEffect, useState } from "react"; import { site } from "@/content"; const CONSENT_KEY = "novarix-cookie-consent"; const REOPEN_EVENT = "novarix:open-cookie-banner"; type Consent = "unknown" | "ack" | "rst"; export default function CookieBanner() { // Hidden by default on the server, then synchronously shown on first paint // if no consent choice exists yet. const [visible, setVisible] = useState(false); // Read the stored consent on mount and decide whether to show the banner. useLayoutEffect(() => { try { const stored = window.localStorage.getItem(CONSENT_KEY) as Consent | null; if (stored !== "ack" && stored !== "rst") { setVisible(true); } } catch { // localStorage unavailable (private mode, blocked, etc.) — show the // banner so the user is still told. setVisible(true); } }, []); // Listen for the "re-open" event from the footer "Cookie preferences" link. useEffect(() => { const handler = () => setVisible(true); window.addEventListener(REOPEN_EVENT, handler); return () => window.removeEventListener(REOPEN_EVENT, handler); }, []); function decide(choice: "ack" | "rst") { try { window.localStorage.setItem(CONSENT_KEY, choice); } catch { /* storage unavailable — nothing to do */ } setVisible(false); } if (!visible) return null; return (
{/* Message + policy link */}

{site.cookies.message}{" "} {site.cookies.policyLabel} →

{/* Buttons */}
); } // Helper used by the footer "Cookie preferences" link to re-open the banner. export function openCookieBanner() { window.dispatchEvent(new Event(REOPEN_EVENT)); }