Skip to content

Commit 33a9023

Browse files
authored
Merge pull request #233 from CivicDataLab/232-add-loader-in-the-place-of-download-report-button-till-report-gets-download
232 add loader in the place of download report button till report gets download
2 parents b0d7ef3 + 15dae84 commit 33a9023

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

app/[locale]/[state]/analytics/components/factor-list.tsx

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ import {
77
RiskScore,
88
Vulnerability,
99
} from '@/public/FactorIcons';
10-
import Hazard from '@/public/Hazard';
1110
import { useQuery } from '@tanstack/react-query';
1211
import { useQueryState } from 'next-usequerystate';
13-
import { Button, Icon, IconButton, Menu, Select, Text, Tooltip } from 'opub-ui';
12+
import { Button, Icon, Menu, Select, Text, Tooltip } from 'opub-ui';
1413

15-
import {
16-
ANALYTICS_INDICATORS,
17-
ANALYTICS_INDICATORS_BY_CATEGORY,
18-
} from '@/config/graphql/analaytics-queries';
14+
import { ANALYTICS_INDICATORS_BY_CATEGORY } from '@/config/graphql/analaytics-queries';
1915
import { GraphQL } from '@/lib/api';
20-
import {
21-
cn,
22-
copyCurrentURL,
23-
downloadStateReport,
24-
handleRedirect,
25-
} from '@/lib/utils';
16+
import { cn, copyCurrentURL, downloadStateReport } from '@/lib/utils';
2617
import Icons from '@/components/icons';
2718
import { MediaRendering } from '@/components/media-rendering';
2819
import RadioButton from './RadioButton';
@@ -214,35 +205,41 @@ export function FactorList({ currentState }: any) {
214205
},
215206
]}
216207
/>
217-
<Button
218-
className="self-start"
219-
onClick={() => {
220-
const confirmation = window.confirm(
221-
`Do you want to download the report for "${currentState.name}". `
222-
);
223-
if (confirmation) {
224-
try {
225-
setDownloadReportLoading(true);
226-
downloadStateReport(
227-
`${process.env.NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL}/report?geo_code=${currentState.code}`,
228-
`${currentState.name}-Report`
229-
);
230-
} catch (error) {
231-
alert(`Error Downloading Report. ${error}`);
232-
} finally {
233-
setDownloadReportLoading(false);
208+
{downloadReportLoading ? (
209+
<Icon source={Icons.loader} className="animate-spin" />
210+
) : (
211+
<Button
212+
className="self-start"
213+
onClick={async () => {
214+
const confirmation = window.confirm(
215+
`Do you want to download the report for "${currentState.name}"?`
216+
);
217+
if (confirmation) {
218+
try {
219+
setDownloadReportLoading(true);
220+
await downloadStateReport(
221+
`${process.env.NEXT_PUBLIC_DATA_MANAGEMENT_LAYER_URL}/report?geo_code=${currentState.code}`,
222+
`${currentState.name}-Report`
223+
);
224+
} catch (error) {
225+
alert(`Error Downloading Report. ${error}`);
226+
} finally {
227+
setDownloadReportLoading(false);
228+
}
234229
}
235-
}
236-
}}
237-
monochrome={true}
238-
kind="tertiary"
239-
// disabled={downloadReportLoading}
240-
>
241-
<div className="flex items-center gap-2">
242-
<Icon source={Icons.download} />
243-
<Text variant="bodyMd">Download Report</Text>
244-
</div>
245-
</Button>
230+
}}
231+
monochrome={true}
232+
kind="tertiary"
233+
234+
// disabled={downloadReportLoading}
235+
>
236+
<div className="flex items-center gap-2">
237+
<Icon source={Icons.download} />
238+
239+
<Text variant="bodyMd">Download Report</Text>
240+
</div>
241+
</Button>
242+
)}
246243
</div>
247244
</div>
248245
</MediaRendering>

components/icons.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
IconLayoutSidebarLeftExpand,
3434
IconLink,
3535
IconListSearch,
36+
IconLoader,
3637
IconMap,
3738
IconMenu,
3839
IconMinus,
@@ -104,6 +105,7 @@ export const Icons: {
104105
IconRefresh: IconRefresh,
105106
IconSwipeUp: IconSwipeUp,
106107
IconSwipeDown: IconSwipeDown,
108+
loader: IconLoader,
107109
};
108110

109111
export default Icons;

0 commit comments

Comments
 (0)