Skip to content

Commit 055fc37

Browse files
committed
ad isEnd to prevent page increment
1 parent f7b62f8 commit 055fc37

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/components/react/NewGallery.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Props {
1414
}
1515

1616
// step
17-
const PAGE_SIZE = 6 as const; // Todo: make it responsive
17+
const PAGE_SIZE = 3 as const; // Todo: make it responsive
1818
// page dependency in useEffect is more important
1919
const INITIAL_PAGE = 1 as const;
2020

@@ -28,6 +28,8 @@ const NewGallery: FC<Props> = ({ images }) => {
2828
const [page, setPage] = useState<number>(INITIAL_PAGE);
2929
const observerTarget = useRef(null);
3030

31+
const isEnd = loadedImages.length === images.length;
32+
3133
// converts page to loaded images
3234
useEffect(() => {
3335
const upToPageImages = fetchImagesUpToPage(images, page);
@@ -37,7 +39,8 @@ const NewGallery: FC<Props> = ({ images }) => {
3739
// sets only page
3840
useEffect(() => {
3941
const callback: IntersectionObserverCallback = (entries) => {
40-
if (entries[0].isIntersecting) {
42+
// Todo: must wait here for images to load
43+
if (!isEnd && entries[0].isIntersecting) {
4144
setPage((prevPage) => prevPage + 1);
4245
}
4346
};
@@ -52,7 +55,7 @@ const NewGallery: FC<Props> = ({ images }) => {
5255
if (observerRef) observer.unobserve(observerRef);
5356
};
5457
// page dependency is important for initial load to work for all resolutions
55-
}, [observerTarget, page]);
58+
}, [observerTarget, page, isEnd]);
5659

5760
// lightbox
5861
useEffect(() => {

0 commit comments

Comments
 (0)