Files
0pt/components/route-reveal.tsx
T
adminandClaude Sonnet 4.6 240a42b2b7 fix: reveal animations for standalone pages on direct load
RouteReveal layout component applies in-view on every route change.
useReveal hook falls back to immediate rAF when element is already visible.
bestall/page.tsx: added missing useReveal ref.
katalog/[id]/page.tsx: DatasetView uses useReveal directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:20:10 +02:00

36 lines
1.2 KiB
TypeScript

"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
const REVEAL_SELECTOR = ".reveal, .reveal-left, .reveal-right, .reveal-scale, .reveal-fade";
/**
* On every route change, applies `.in-view` to any reveal element whose
* top edge is already within the viewport. This handles standalone pages
* (like /bestall, /katalog/[id]) that are fully visible on load, where
* IntersectionObserver alone may not fire before the user sees blank content.
*/
export function RouteReveal() {
const pathname = usePathname();
useEffect(() => {
const vh = window.innerHeight;
const apply = () => {
document.querySelectorAll<HTMLElement>(REVEAL_SELECTOR).forEach((el) => {
if (!el.classList.contains("in-view")) {
const { top } = el.getBoundingClientRect();
if (top < vh * 0.95) el.classList.add("in-view");
}
});
};
// Two passes: immediate + after paint (for async-loaded content).
apply();
const raf = requestAnimationFrame(apply);
const t = setTimeout(apply, 600);
return () => { cancelAnimationFrame(raf); clearTimeout(t); };
}, [pathname]);
return null;
}