.
This commit is contained in:
@@ -111,9 +111,6 @@
|
|||||||
@layer base {
|
@layer base {
|
||||||
html {
|
html {
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,10 +136,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
html[data-ui-ready="0"] body {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------
|
/* ---------------------------------------------------------------------------
|
||||||
4. Site shell + ambient effects
|
4. Site shell + ambient effects
|
||||||
The .site-shell class is on the <main> element in page.tsx. The two
|
The .site-shell class is on the <main> element in page.tsx. The two
|
||||||
|
|||||||
+1
-26
@@ -62,32 +62,7 @@ export default function RootLayout({
|
|||||||
children,
|
children,
|
||||||
}: Readonly<{ children: React.ReactNode }>) {
|
}: Readonly<{ children: React.ReactNode }>) {
|
||||||
return (
|
return (
|
||||||
<html lang="en-GB" suppressHydrationWarning data-ui-ready="0">
|
<html lang="en-GB" suppressHydrationWarning>
|
||||||
<head>
|
|
||||||
<script
|
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: `
|
|
||||||
(function () {
|
|
||||||
var root = document.documentElement;
|
|
||||||
root.dataset.uiReady = "0";
|
|
||||||
try {
|
|
||||||
var consent = window.localStorage.getItem("novarix-cookie-consent");
|
|
||||||
var introSeen = window.sessionStorage.getItem("novarix-intro-seen");
|
|
||||||
var shouldShowBanner = consent !== "ack" && consent !== "rst";
|
|
||||||
var shouldPlayIntro = !shouldShowBanner && !introSeen;
|
|
||||||
|
|
||||||
root.dataset.showCookieBanner = shouldShowBanner ? "1" : "0";
|
|
||||||
root.dataset.showIntro = shouldPlayIntro ? "1" : "0";
|
|
||||||
} catch (error) {
|
|
||||||
root.dataset.showCookieBanner = "1";
|
|
||||||
root.dataset.showIntro = "0";
|
|
||||||
}
|
|
||||||
root.dataset.uiReady = "1";
|
|
||||||
})();
|
|
||||||
`,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
{children}
|
{children}
|
||||||
<CookieBanner />
|
<CookieBanner />
|
||||||
|
|||||||
+7
-20
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useLayoutEffect, useMemo, useState } from "react";
|
||||||
import { site } from "@/content";
|
import { site } from "@/content";
|
||||||
import { openCookieBanner } from "@/components/CookieBanner";
|
import { openCookieBanner } from "@/components/CookieBanner";
|
||||||
|
|
||||||
@@ -42,23 +42,18 @@ export default function HomePage() {
|
|||||||
// pointer — the mouse position (in % of page width/height). Used by the
|
// pointer — the mouse position (in % of page width/height). Used by the
|
||||||
// soft glow that follows the cursor in the background.
|
// soft glow that follows the cursor in the background.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
const [showIntro, setShowIntro] = useState(() => {
|
const [showIntro, setShowIntro] = useState(false);
|
||||||
if (typeof document === "undefined") return false;
|
|
||||||
return document.documentElement.dataset.showIntro === "1";
|
|
||||||
});
|
|
||||||
const [pointer, setPointer] = useState<PointerState>({ x: 50, y: 22 });
|
const [pointer, setPointer] = useState<PointerState>({ x: 50, y: 22 });
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// INTRO OVERLAY EFFECT
|
// INTRO OVERLAY EFFECT
|
||||||
// Plays the animated logo + wordmark the first time someone visits the
|
// Plays the animated logo + wordmark the first time someone visits the
|
||||||
// site in this browser tab. We decide before hydration whether to play it,
|
// site in this browser tab. The initial check runs in useLayoutEffect so
|
||||||
// which avoids the homepage flashing briefly before the intro appears.
|
// the intro can mount before the first browser paint, avoiding a visible
|
||||||
// After the user accepts cookies on their first visit, we trigger the intro
|
// flash of the homepage underneath.
|
||||||
// immediately from the banner close action.
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
function playIntro() {
|
function playIntro() {
|
||||||
document.documentElement.dataset.showIntro = "1";
|
|
||||||
setShowIntro(true);
|
setShowIntro(true);
|
||||||
try {
|
try {
|
||||||
window.sessionStorage.setItem(INTRO_SEEN_KEY, "true");
|
window.sessionStorage.setItem(INTRO_SEEN_KEY, "true");
|
||||||
@@ -67,7 +62,6 @@ export default function HomePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const timer = window.setTimeout(() => {
|
const timer = window.setTimeout(() => {
|
||||||
document.documentElement.dataset.showIntro = "0";
|
|
||||||
setShowIntro(false);
|
setShowIntro(false);
|
||||||
}, 3950);
|
}, 3950);
|
||||||
|
|
||||||
@@ -79,21 +73,14 @@ export default function HomePage() {
|
|||||||
try {
|
try {
|
||||||
const introSeen = window.sessionStorage.getItem(INTRO_SEEN_KEY);
|
const introSeen = window.sessionStorage.getItem(INTRO_SEEN_KEY);
|
||||||
const consent = window.localStorage.getItem("novarix-cookie-consent");
|
const consent = window.localStorage.getItem("novarix-cookie-consent");
|
||||||
const shouldPlayNow =
|
const shouldPlayNow = consent === "ack" && !introSeen;
|
||||||
document.documentElement.dataset.showIntro === "1" &&
|
|
||||||
consent === "ack" &&
|
|
||||||
!introSeen;
|
|
||||||
|
|
||||||
if (shouldPlayNow) {
|
if (shouldPlayNow) {
|
||||||
timer = playIntro();
|
timer = playIntro();
|
||||||
} else {
|
} else {
|
||||||
document.documentElement.dataset.showIntro = "0";
|
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
||||||
setShowIntro(false);
|
setShowIntro(false);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
document.documentElement.dataset.showIntro = "0";
|
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
||||||
setShowIntro(false);
|
setShowIntro(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useLayoutEffect, useState } from "react";
|
||||||
import { site } from "@/content";
|
import { site } from "@/content";
|
||||||
|
|
||||||
const CONSENT_KEY = "novarix-cookie-consent";
|
const CONSENT_KEY = "novarix-cookie-consent";
|
||||||
@@ -33,30 +33,20 @@ const INTRO_EVENT = "novarix:start-intro";
|
|||||||
type Consent = "unknown" | "ack" | "rst";
|
type Consent = "unknown" | "ack" | "rst";
|
||||||
|
|
||||||
export default function CookieBanner() {
|
export default function CookieBanner() {
|
||||||
// Start from the pre-hydration decision made in layout.tsx so the banner
|
// Hidden by default on the server, then synchronously shown on first paint
|
||||||
// can appear immediately on first visit without waiting for a delayed effect.
|
// if no consent choice exists yet.
|
||||||
const [visible, setVisible] = useState(() => {
|
const [visible, setVisible] = useState(false);
|
||||||
if (typeof document === "undefined") return false;
|
|
||||||
return document.documentElement.dataset.showCookieBanner === "1";
|
|
||||||
});
|
|
||||||
|
|
||||||
// Read the stored consent on mount and decide whether to show the banner.
|
// Read the stored consent on mount and decide whether to show the banner.
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
try {
|
try {
|
||||||
const stored = window.localStorage.getItem(CONSENT_KEY) as Consent | null;
|
const stored = window.localStorage.getItem(CONSENT_KEY) as Consent | null;
|
||||||
if (stored !== "ack" && stored !== "rst") {
|
if (stored !== "ack" && stored !== "rst") {
|
||||||
document.documentElement.dataset.showCookieBanner = "1";
|
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
} else {
|
|
||||||
document.documentElement.dataset.showCookieBanner = "0";
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// localStorage unavailable (private mode, blocked, etc.) — show the
|
// localStorage unavailable (private mode, blocked, etc.) — show the
|
||||||
// banner so the user is still told. Sync-once-on-mount is a legitimate
|
// banner so the user is still told.
|
||||||
// use of setState in an effect.
|
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
||||||
document.documentElement.dataset.showCookieBanner = "1";
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
@@ -80,7 +70,6 @@ export default function CookieBanner() {
|
|||||||
} catch {
|
} catch {
|
||||||
/* storage unavailable — nothing to do */
|
/* storage unavailable — nothing to do */
|
||||||
}
|
}
|
||||||
document.documentElement.dataset.showCookieBanner = "0";
|
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user