v2: global player, infinite scroll, image picker, threaded comments

This commit is contained in:
khannurien
2026-03-21 13:55:22 +00:00
parent be426eb150
commit 7c098e7c4c
48 changed files with 4346 additions and 711 deletions

View File

@@ -0,0 +1,26 @@
import { useCallback, useEffect, useRef } from "react";
export function useInfiniteScroll(onLoadMore: () => void, enabled: boolean) {
const sentinelRef = useRef<HTMLDivElement>(null);
const handleIntersect = useCallback(
(entries: IntersectionObserverEntry[]) => {
if (entries[0].isIntersecting && enabled) {
onLoadMore();
}
},
[onLoadMore, enabled],
);
useEffect(() => {
const el = sentinelRef.current;
if (!el) return;
const observer = new IntersectionObserver(handleIntersect, {
rootMargin: "200px",
});
observer.observe(el);
return () => observer.disconnect();
}, [handleIntersect]);
return sentinelRef;
}