Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Mar 27, 2024
1 parent 400c906 commit 40325e5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions databox/client/src/components/AssetList/LoadMoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function LoadMoreButton<Item extends AssetOrAssetContainer>({onCl
const [loading, setLoading] = React.useState(false);
const ref = React.useRef<HTMLDivElement>();
const loadingRef = React.useRef(false);
const scrollableNode = ref.current?.closest(`.${assetClasses.scrollable}`);

const doLoad = React.useCallback(() => {
if (loadingRef.current) {
Expand All @@ -35,11 +34,13 @@ export default function LoadMoreButton<Item extends AssetOrAssetContainer>({onCl

React.useLayoutEffect(() => {
if (pages[0]) {
const scrollableNode = ref.current?.closest(`.${assetClasses.scrollable}`);
scrollableNode?.scrollTo({top: 0, left: 0});
}
}, [pages[0], scrollableNode]);
}, [pages[0], ref]);

React.useEffect(() => {
const scrollableNode = ref.current?.closest(`.${assetClasses.scrollable}`);
if (scrollableNode) {
const onScrollEnd = (e: HTMLElementEventMap['scroll']) => {
const {scrollTop, scrollHeight, clientHeight} = e.currentTarget as HTMLDivElement;
Expand All @@ -53,7 +54,7 @@ export default function LoadMoreButton<Item extends AssetOrAssetContainer>({onCl
scrollableNode.removeEventListener('scroll', onScrollEnd);
}
}
}, [doLoad, scrollableNode]);
}, [doLoad, ref]);

return (
<Box
Expand Down

0 comments on commit 40325e5

Please sign in to comment.