Skip to content

Commit

Permalink
#179 | Remove unnecessary API calls to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Oct 23, 2024
1 parent 8b67df6 commit 0ba4123
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
33 changes: 6 additions & 27 deletions client/components/ImageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {MediaSearchService} from "@/service/MediaSearchService";
import Loading from '@/components/loading';

interface Props {
imageList: object[];
imageList: imageType[];
totalRecords: any;
carouselImage: any;
currentPage: any;
Expand All @@ -22,43 +22,21 @@ interface Props {
checkedImage: string[];
setCheckedImage: string[];
dataBody: any;
minLevelName: string;
}

const ImageCarousel = ({
imageList,
totalRecords,
carouselImage,
currentPage,
showPerpage,
onClose,
onSelectImage,
checkedImage,
dataBody
minLevelName
}: Props) => {
const ci = carouselImage as never;
const index = imageList.indexOf(ci);
const [images, setImages] = useState([]);
const [showLoader, setShowLoader] = useState(false);
const [minLevelName, setMinLevelName] = useState<string>('');

useEffect(() => {
const filterData = async () => {
const processedData = await operationalModuleData()
setMinLevelName(processedData.minLevelAddressName)
};
filterData();
}, []);

useEffect(() => {
redirectIfNotValid();
const fetchImages = async () => {
setShowLoader(true);
const responseData = await MediaSearchService.searchMedia(dataBody, currentPage, showPerpage);
setImages(responseData.data);
setShowLoader(false);
};
fetchImages();
}, [totalRecords]);

const onSelectImageCarousel = (value: string, checked: boolean) => {
onSelectImage(value, checked,);
Expand All @@ -77,7 +55,8 @@ const ImageCarousel = ({
`${process.env.NEXT_PUBLIC_WEB}/web/individual/byMetadata`,
options
);
window.location.href = buildSubjectDashboardURLForUUID(response.data.uuid);
const newWindow = window.open(buildSubjectDashboardURLForUUID(response.data.uuid), '_blank', 'noopener,noreferrer');
if (newWindow) newWindow.opener = null;
return;
};

Expand Down Expand Up @@ -151,7 +130,7 @@ const ImageCarousel = ({
dynamicHeight={false}
useKeyboardArrows={true}
>
{images.map(
{imageList.map(
(
img: imageType,
index
Expand Down
1 change: 1 addition & 0 deletions client/components/ImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ export default function ImageList() {
checkedImage={checkedImage}
setCheckedImage={[]}
dataBody={dataBody}
minLevelName={minLevelName}
/>
)}
<Pagination
Expand Down

0 comments on commit 0ba4123

Please sign in to comment.