Skip to content

Commit

Permalink
Refactor infiniteScoll to use debouncing (#5999)
Browse files Browse the repository at this point in the history
Same as #5996 but with
useDebounced as asked in review
  • Loading branch information
charlesBochet authored Jun 24, 2024
1 parent 2e4ba9c commit 498e4ff
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
import { useRecoilValue } from 'recoil';
import { useDebouncedCallback } from 'use-debounce';

import { useLoadRecordIndexTable } from '@/object-record/record-index/hooks/useLoadRecordIndexTable';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
Expand Down Expand Up @@ -41,14 +42,20 @@ export const RecordTableBodyEffect = ({
}
}, [records, totalCount, setRecordTableData, loading]);

const fetchMoreDebouncedIfRequested = useDebouncedCallback(async () => {
// We are debouncing here to give the user some room to scroll if they want to within this throttle window
await fetchMoreObjects();
}, 100);

useEffect(() => {
// We are adding a setTimeout here to give the user some room to scroll if they want to within this throttle window
setTimeout(async () => {
if (!isFetchingMoreObjects && tableLastRowVisible) {
await fetchMoreObjects();
}
}, 100);
}, [fetchMoreObjects, isFetchingMoreObjects, tableLastRowVisible]);
if (!isFetchingMoreObjects && tableLastRowVisible) {
fetchMoreDebouncedIfRequested();
}
}, [
fetchMoreDebouncedIfRequested,
isFetchingMoreObjects,
tableLastRowVisible,
]);

return <></>;
};

0 comments on commit 498e4ff

Please sign in to comment.