From d02fcfc0374679fd40302ffc688ce456310f8aba Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Mon, 30 May 2022 13:00:19 +1000 Subject: [PATCH] add console logs to troubleshoot infinite scroll on production --- src/atoms/tableScope/table.ts | 1 + src/components/Table/Table.tsx | 2 +- src/hooks/useFirestoreCollectionWithAtom.ts | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/atoms/tableScope/table.ts b/src/atoms/tableScope/table.ts index 32569b16..5b276d1d 100644 --- a/src/atoms/tableScope/table.ts +++ b/src/atoms/tableScope/table.ts @@ -76,6 +76,7 @@ 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); diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index dc1774c3..50673813 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -170,7 +170,7 @@ export default function Table() { const isAtBottom = target.clientHeight + target.scrollTop >= target.scrollHeight - offset; if (!isAtBottom) return; - console.log("Scroll"); + console.log("Scrolled to bottom"); // Call for the next page setTablePage((p) => p + 1); }, diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 50e00101..b2c3cd3f 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -147,6 +147,7 @@ export function useFirestoreCollectionWithAtom( // 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 @@ -170,6 +171,12 @@ export function useFirestoreCollectionWithAtom( 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);