From 6e436c7ee4f2a60e7879ddb295da3169097486ac Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Wed, 20 Sep 2023 21:44:30 -0500 Subject: [PATCH] Fix infinite scroll --- src/cache/index.ts | 6 +++--- src/components/MorePhotos.tsx | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cache/index.ts b/src/cache/index.ts index a3e9af55..39da6d0d 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -26,9 +26,9 @@ const getPhotosCacheTags = (options: GetPhotosOptions = {}) => { } = options; if (sortBy !== undefined) { tags.push(`sortBy-${sortBy}`); } - if (limit !== undefined) { tags.push(`limit-${sortBy}`); } - if (offset !== undefined) { tags.push(`offset-${sortBy}`); } - if (tag !== undefined) { tags.push(`tag-${sortBy}`); } + if (limit !== undefined) { tags.push(`limit-${limit}`); } + if (offset !== undefined) { tags.push(`offset-${offset}`); } + if (tag !== undefined) { tags.push(`tag-${tag}`); } // eslint-disable-next-line max-len if (takenBefore !== undefined) { tags.push(`takenBefore-${takenBefore.toISOString()}`); } // eslint-disable-next-line max-len diff --git a/src/components/MorePhotos.tsx b/src/components/MorePhotos.tsx index 2774eebf..dadcd616 100644 --- a/src/components/MorePhotos.tsx +++ b/src/components/MorePhotos.tsx @@ -31,7 +31,11 @@ export default function MorePhotos({ useEffect(() => { const observer = new IntersectionObserver(e => { - if (triggerOnView && e[0].isIntersecting) { + if ( + triggerOnView && + e[0].isIntersecting && + !isPending + ) { advance(); } }, { @@ -42,7 +46,7 @@ export default function MorePhotos({ observer.observe(buttonRef.current!); return () => observer.disconnect(); - }, [triggerOnView, advance]); + }, [triggerOnView, advance, isPending]); return (