mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-14 22:52:15 +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 [metadataJson, setMetadataJson] = useState<Record<string, unknown> | null>(null);
|
||||||
const [metadataLoading, setMetadataLoading] = useState(false);
|
const [metadataLoading, setMetadataLoading] = useState(false);
|
||||||
const [previewScrollPos, setPreviewScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
const [previewScrollPos, setPreviewScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
||||||
|
const previewRafRef = useRef<number>();
|
||||||
const handlePreviewScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
const handlePreviewScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||||
const el = e.currentTarget;
|
const el = e.currentTarget;
|
||||||
const atTop = el.scrollTop <= 2;
|
if (previewRafRef.current) return;
|
||||||
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
previewRafRef.current = requestAnimationFrame(() => {
|
||||||
setPreviewScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
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 [deleteDoc, setDeleteDoc] = useState<Document | null>(null);
|
||||||
const [isDeleting, setIsDeleting] = useState(false);
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -817,12 +817,23 @@ const ComposerAction: FC<ComposerActionProps> = ({ isBlockedByOtherUser = false
|
||||||
const isDesktop = useMediaQuery("(min-width: 640px)");
|
const isDesktop = useMediaQuery("(min-width: 640px)");
|
||||||
const { openDialog: openUploadDialog } = useDocumentUploadDialog();
|
const { openDialog: openUploadDialog } = useDocumentUploadDialog();
|
||||||
const [toolsScrollPos, setToolsScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
const [toolsScrollPos, setToolsScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
||||||
|
const toolsRafRef = useRef<number>();
|
||||||
const handleToolsScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
const handleToolsScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||||
const el = e.currentTarget;
|
const el = e.currentTarget;
|
||||||
const atTop = el.scrollTop <= 2;
|
if (toolsRafRef.current) return;
|
||||||
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
toolsRafRef.current = requestAnimationFrame(() => {
|
||||||
setToolsScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
const atTop = el.scrollTop <= 2;
|
||||||
|
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
||||||
|
setToolsScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
||||||
|
toolsRafRef.current = undefined;
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
if (toolsRafRef.current) cancelAnimationFrame(toolsRafRef.current);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
const isComposerTextEmpty = useAuiState(({ composer }) => {
|
const isComposerTextEmpty = useAuiState(({ composer }) => {
|
||||||
const text = composer.text?.trim() || "";
|
const text = composer.text?.trim() || "";
|
||||||
return text.length === 0;
|
return text.length === 0;
|
||||||
|
|
|
||||||
|
|
@ -178,12 +178,23 @@ export function InboxSidebarContent({
|
||||||
const [mounted, setMounted] = useState(false);
|
const [mounted, setMounted] = useState(false);
|
||||||
const [openDropdown, setOpenDropdown] = useState<"filter" | null>(null);
|
const [openDropdown, setOpenDropdown] = useState<"filter" | null>(null);
|
||||||
const [connectorScrollPos, setConnectorScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
const [connectorScrollPos, setConnectorScrollPos] = useState<"top" | "middle" | "bottom">("top");
|
||||||
|
const connectorRafRef = useRef<number>();
|
||||||
const handleConnectorScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
const handleConnectorScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {
|
||||||
const el = e.currentTarget;
|
const el = e.currentTarget;
|
||||||
const atTop = el.scrollTop <= 2;
|
if (connectorRafRef.current) return;
|
||||||
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
connectorRafRef.current = requestAnimationFrame(() => {
|
||||||
setConnectorScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
const atTop = el.scrollTop <= 2;
|
||||||
|
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= 2;
|
||||||
|
setConnectorScrollPos(atTop ? "top" : atBottom ? "bottom" : "middle");
|
||||||
|
connectorRafRef.current = undefined;
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
if (connectorRafRef.current) cancelAnimationFrame(connectorRafRef.current);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
const [filterDrawerOpen, setFilterDrawerOpen] = useState(false);
|
const [filterDrawerOpen, setFilterDrawerOpen] = useState(false);
|
||||||
const [markingAsReadId, setMarkingAsReadId] = useState<number | null>(null);
|
const [markingAsReadId, setMarkingAsReadId] = useState<number | null>(null);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue