Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexd-bes committed Sep 18, 2024
1 parent 653ab43 commit 48ec638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { URL_SEARCH_PARAMS } from '../../../../constants';
import { useDashboard } from '../../../Dashboard';
import { useDownloadImages } from './useDownloadImages';
import { ExportIconButton } from '../../../EnlargedDashboardItem';
import { SmallAlert } from '@tupaia/ui-components';

const Wrapper = styled.div`
position: relative;
Expand Down Expand Up @@ -157,13 +158,11 @@ export const MultiPhotographEnlarged = ({ report, config }: MultiPhotographEnlar
const { projectCode, entityCode } = useParams();
const { activeDashboard } = useDashboard();

const { mutate: downloadImages, isLoading } = useDownloadImages(
projectCode,
entityCode,
activeDashboard?.code,
reportCode,
data,
);
const {
mutate: downloadImages,
isLoading,
error,
} = useDownloadImages(projectCode, entityCode, activeDashboard?.code, reportCode, data);

useEffect(() => {
if (!sliderRef1.current || mainSlider) return;
Expand Down Expand Up @@ -232,8 +231,10 @@ export const MultiPhotographEnlarged = ({ report, config }: MultiPhotographEnlar
isLoading={isLoading}
title="Export images"
/>

<Wrapper>
<MainSliderContainer>
{error && <SmallAlert severity="error">{(error as Error).message}</SmallAlert>}
<Slider
{...settings}
asNavFor={thumbnailSlider}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export const useDownloadImages = (
['images', projectCode, entityCode, dashboardCode, reportCode],
async () => {
return Promise.all(
images?.map(photo =>
fetch(photo.value, {
images?.map(photo => {
return fetch(photo.value, {
method: 'GET',
}).then(async response => {
return {
blob: await response.blob(),
label: photo.label,
};
}),
) ?? [],
});
}) ?? [],
);
},
{
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useDownloadImages = (
return blobsWithNames.push({ blob, name: label });
}
// Default to Image 1, Image 2, etc.
blobsWithNames.push({ blob, name: `${reportCode}_image_${index + 1}` });
blobsWithNames.push({ blob, name: `Image ${index + 1}` });
});

const zip = new JSZip();
Expand Down

0 comments on commit 48ec638

Please sign in to comment.