@@ -7,22 +7,13 @@ import {
77 RiskScore ,
88 Vulnerability ,
99} from '@/public/FactorIcons' ;
10- import Hazard from '@/public/Hazard' ;
1110import { useQuery } from '@tanstack/react-query' ;
1211import { 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' ;
1915import { 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' ;
2617import Icons from '@/components/icons' ;
2718import { MediaRendering } from '@/components/media-rendering' ;
2819import 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 >
0 commit comments