mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
fix table infinite scroll stopping after a while because the network doesn’t load all available docs, and we set the internal hook state to prevent getting new pages
This commit is contained in:
@@ -76,7 +76,6 @@ export const tablePageAtom = atom(
|
||||
(get, set, update: number | ((p: number) => number)) => {
|
||||
// If loading more or doesn’t have next page, don’t request another page
|
||||
const tableNextPage = get(tableNextPageAtom);
|
||||
console.log("Next page requested", JSON.stringify(tableNextPage));
|
||||
if (tableNextPage.loading || !tableNextPage.available) return;
|
||||
|
||||
const currentPage = get(tablePageAtom);
|
||||
|
||||
@@ -170,7 +170,6 @@ export default function Table() {
|
||||
const isAtBottom =
|
||||
target.clientHeight + target.scrollTop >= target.scrollHeight - offset;
|
||||
if (!isAtBottom) return;
|
||||
console.log("Scrolled to bottom");
|
||||
// Call for the next page
|
||||
setTablePage((p) => p + 1);
|
||||
},
|
||||
|
||||
@@ -147,7 +147,6 @@ export function useFirestoreCollectionWithAtom<T = TableRow>(
|
||||
// Set nextPageAtom if provided and getting the next page
|
||||
else if (memoizedQuery.page > 0 && nextPageAtom) {
|
||||
setNextPageAtom((s) => ({ ...s, loading: true }));
|
||||
console.log("Loading next page", memoizedQuery.page);
|
||||
}
|
||||
|
||||
// Create a listener for the query
|
||||
@@ -163,6 +162,8 @@ export function useFirestoreCollectionWithAtom<T = TableRow>(
|
||||
setDataAtom(docs);
|
||||
// If the snapshot doesn’t fill the page, it’s the last page
|
||||
if (docs.length < memoizedQuery.limit) setIsLastPage(true);
|
||||
// Make sure to unset in case of mistake
|
||||
else setIsLastPage(false);
|
||||
// Update nextPageAtom if provided
|
||||
if (nextPageAtom) {
|
||||
setNextPageAtom((s) => ({
|
||||
@@ -171,12 +172,6 @@ export function useFirestoreCollectionWithAtom<T = TableRow>(
|
||||
available: docs.length >= memoizedQuery.limit,
|
||||
}));
|
||||
}
|
||||
console.log(
|
||||
"Loaded next page",
|
||||
memoizedQuery.page,
|
||||
" Next page available:",
|
||||
docs.length >= memoizedQuery.limit
|
||||
);
|
||||
} catch (error) {
|
||||
if (onError) onError(error as FirestoreError);
|
||||
else handleError(error);
|
||||
|
||||
Reference in New Issue
Block a user