.
This commit is contained in:
+7
-20
@@ -25,7 +25,7 @@
|
||||
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useLayoutEffect, useMemo, useState } from "react";
|
||||
import { site } from "@/content";
|
||||
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
|
||||
// soft glow that follows the cursor in the background.
|
||||
// ---------------------------------------------------------------------------
|
||||
const [showIntro, setShowIntro] = useState(() => {
|
||||
if (typeof document === "undefined") return false;
|
||||
return document.documentElement.dataset.showIntro === "1";
|
||||
});
|
||||
const [showIntro, setShowIntro] = useState(false);
|
||||
const [pointer, setPointer] = useState<PointerState>({ x: 50, y: 22 });
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// INTRO OVERLAY EFFECT
|
||||
// Plays the animated logo + wordmark the first time someone visits the
|
||||
// site in this browser tab. We decide before hydration whether to play it,
|
||||
// which avoids the homepage flashing briefly before the intro appears.
|
||||
// After the user accepts cookies on their first visit, we trigger the intro
|
||||
// immediately from the banner close action.
|
||||
// site in this browser tab. The initial check runs in useLayoutEffect so
|
||||
// the intro can mount before the first browser paint, avoiding a visible
|
||||
// flash of the homepage underneath.
|
||||
// ---------------------------------------------------------------------------
|
||||
useEffect(() => {
|
||||
useLayoutEffect(() => {
|
||||
function playIntro() {
|
||||
document.documentElement.dataset.showIntro = "1";
|
||||
setShowIntro(true);
|
||||
try {
|
||||
window.sessionStorage.setItem(INTRO_SEEN_KEY, "true");
|
||||
@@ -67,7 +62,6 @@ export default function HomePage() {
|
||||
}
|
||||
|
||||
const timer = window.setTimeout(() => {
|
||||
document.documentElement.dataset.showIntro = "0";
|
||||
setShowIntro(false);
|
||||
}, 3950);
|
||||
|
||||
@@ -79,21 +73,14 @@ export default function HomePage() {
|
||||
try {
|
||||
const introSeen = window.sessionStorage.getItem(INTRO_SEEN_KEY);
|
||||
const consent = window.localStorage.getItem("novarix-cookie-consent");
|
||||
const shouldPlayNow =
|
||||
document.documentElement.dataset.showIntro === "1" &&
|
||||
consent === "ack" &&
|
||||
!introSeen;
|
||||
const shouldPlayNow = consent === "ack" && !introSeen;
|
||||
|
||||
if (shouldPlayNow) {
|
||||
timer = playIntro();
|
||||
} else {
|
||||
document.documentElement.dataset.showIntro = "0";
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setShowIntro(false);
|
||||
}
|
||||
} catch {
|
||||
document.documentElement.dataset.showIntro = "0";
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setShowIntro(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user