Fix infinite scroll

This commit is contained in:
Sam Becker 2023-09-20 21:44:30 -05:00
parent 1957de483c
commit 6e436c7ee4
2 changed files with 9 additions and 5 deletions

6
src/cache/index.ts vendored
View File

@ -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

View File

@ -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 (
<button