From 4b6db09208354156aae277eba602a49646b7d41d Mon Sep 17 00:00:00 2001 From: Joy A Date: Wed, 20 Nov 2024 13:21:06 +0530 Subject: [PATCH] #179 | Media display performance improvements - Fetch only one page of search results - Don't request all full-res images on load when carousel is displayed --- client/components/ImageCarousel.tsx | 18 ++++++++++++++---- client/components/ImageList.tsx | 6 ++---- client/components/Pagination.tsx | 16 ++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/client/components/ImageCarousel.tsx b/client/components/ImageCarousel.tsx index d50dfc6..8182940 100644 --- a/client/components/ImageCarousel.tsx +++ b/client/components/ImageCarousel.tsx @@ -15,6 +15,7 @@ interface Props { imageList: imageType[]; totalRecords: any; carouselImage: any; + setCarouselImage: any; currentPage: any; showPerpage: any, onClose: () => void; @@ -31,7 +32,8 @@ const ImageCarousel = ({ onClose, onSelectImage, checkedImage, - minLevelName + minLevelName, + setCarouselImage }: Props) => { const ci = carouselImage as never; const index = imageList.indexOf(ci); @@ -99,24 +101,32 @@ const ImageCarousel = ({ {showLoader && } { + const customClickHandler = () => { + setCarouselImage(imageList[index - 1]); + clickHandler(); + } return (
); }} renderArrowNext={(clickHandler, hasNext) => { + const customClickHandler = () => { + setCarouselImage(imageList[index + 1]); + clickHandler(); + } return (
@@ -136,7 +146,7 @@ const ImageCarousel = ({ index ) => (
- +
{ setShowLoader(true); const responseData = await MediaSearchService.searchMedia(dataBody, currentPage, showPerpage); - const nextPageResponseData = await MediaSearchService.searchMedia(dataBody, currentPage + 1, showPerpage); - setImageList(responseData); setShowLoader(false); - setNextPageData(nextPageResponseData); }; fetchImages(); @@ -943,12 +940,13 @@ export default function ImageList() { setCheckedImage={[]} dataBody={dataBody} minLevelName={minLevelName} + setCarouselImage={setCarouselImage} /> )} }
diff --git a/client/components/Pagination.tsx b/client/components/Pagination.tsx index 8a89c30..de99efe 100644 --- a/client/components/Pagination.tsx +++ b/client/components/Pagination.tsx @@ -4,22 +4,14 @@ import { useState, useEffect } from 'react'; interface Props { showperpage: number; pagechange: (pageNumber: number) => void; - nextPageData: any[]; + enableNextPage: boolean; } - const Pagination = ({ showperpage, pagechange, nextPageData }: Props) => { + const Pagination = ({ showperpage, pagechange, enableNextPage }: Props) => { const [counter, setCounter] = useState(1) - const page = Math.ceil(nextPageData.length / showperpage) - useEffect(() => { - - if (counter == page) { pagechange(counter - 1) - } - else { - pagechange(counter -1 ) - } }, [counter, showperpage]) @@ -33,7 +25,7 @@ interface Props { } } else if (type == "next") { - if (nextPageData.length >= 1) { + if (enableNextPage) { setCounter(counter + 1) } else{ @@ -67,7 +59,7 @@ interface Props {