v3: code quality pass

This commit is contained in:
khannurien
2026-03-24 18:47:05 +00:00
parent cd4076343b
commit c293f3e706
39 changed files with 1464 additions and 1555 deletions

View File

@@ -0,0 +1,24 @@
import { useEffect } from "react";
/**
* Sets up a debounced scroll listener that calls `onSave(scrollY)` when the
* user scrolls, but only while `enabled` is true (e.g. the page is loaded).
*/
export function useScrollSave(
enabled: boolean,
onSave: (scrollY: number) => void,
) {
useEffect(() => {
if (!enabled) return;
let timer: ReturnType<typeof setTimeout>;
const onScroll = () => {
clearTimeout(timer);
timer = setTimeout(() => onSave(globalThis.scrollY), 100);
};
globalThis.addEventListener("scroll", onScroll, { passive: true });
return () => {
globalThis.removeEventListener("scroll", onScroll);
clearTimeout(timer);
};
}, [enabled, onSave]);
}