Add InsightFace/OpenCV challenge upload, PC vs mobile capture branching, and fix avatar persistence into roster/profile pages. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
/** Observe `.reveal` inside a root selector and mark `.visible` once. */
|
|
export function useRevealMotion(rootSelector: string, deps: unknown[] = []) {
|
|
useEffect(() => {
|
|
if (!rootSelector) return;
|
|
const root = document.querySelector(rootSelector);
|
|
if (!root) return;
|
|
const media = matchMedia("(prefers-reduced-motion: reduce)");
|
|
const observer = new IntersectionObserver(
|
|
(entries) =>
|
|
entries.forEach((entry) => {
|
|
if (!entry.isIntersecting) return;
|
|
entry.target.classList.add("visible");
|
|
observer.unobserve(entry.target);
|
|
}),
|
|
{ threshold: 0.08, rootMargin: "0px 0px -20px 0px" },
|
|
);
|
|
const scan = () => {
|
|
root
|
|
.querySelectorAll(".reveal:not(.visible)")
|
|
.forEach((el) => {
|
|
if (media.matches) el.classList.add("visible");
|
|
else observer.observe(el);
|
|
});
|
|
};
|
|
scan();
|
|
// Searches, remote catalogs and empty states mount after the initial render.
|
|
const mutations = new MutationObserver(scan);
|
|
mutations.observe(root, { childList: true, subtree: true });
|
|
media.addEventListener("change", scan);
|
|
return () => {
|
|
mutations.disconnect();
|
|
media.removeEventListener("change", scan);
|
|
observer.disconnect();
|
|
};
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- caller owns deps
|
|
}, deps);
|
|
}
|