mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-02 22:01:05 +02:00
Merge pull request #1108 from mvanhorn/perf/throttle-scroll-handlers
perf: throttle scroll handlers with requestAnimationFrame
This commit is contained in:
commit
d8231c2002
3 changed files with 42 additions and 9 deletions
|
|
@ -267,12 +267,23 @@ export function DocumentsTableShell({
|
|||
const [metadataJson, setMetadataJson] = useState<Record<string, unknown> | null>(null);
|
||||
const [metadataLoading, setMetadataLoading] = useState(false);
|
||||
const [previewScrollPos, setPreviewScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
||||
const previewRafRef = useRef<number>();
|
||||
const handlePreviewScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||
const el = e.currentTarget;
|
||||
const atTop = el.scrollTop <= 2;
|
||||
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
||||
setPreviewScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
||||
if (previewRafRef.current) return;
|
||||
previewRafRef.current = requestAnimationFrame(() => {
|
||||
const atTop = el.scrollTop <= 2;
|
||||
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
||||
setPreviewScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
||||
previewRafRef.current = undefined;
|
||||
});
|
||||
}, []);
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (previewRafRef.current) cancelAnimationFrame(previewRafRef.current);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const [deleteDoc, setDeleteDoc] = useState<Document | null>(null);
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue