11import { useMemo } from 'react' ;
22import { useParams , useOutletContext } from 'react-router-dom' ;
3- import { isDefined } from '@togglecorp/fujs' ;
3+ import { isDefined , isNotDefined , mapToList } from '@togglecorp/fujs' ;
44import getBbox from '@turf/bbox' ;
55
66import Container from '#components/Container' ;
77import Link from '#components/Link' ;
88import RiskImminentEvents from '#components/domain/RiskImminentEvents' ;
99import HistoricalDataChart from '#components/domain/HistoricalDataChart' ;
10+ import BlockLoading from '#components/BlockLoading' ;
1011import useTranslation from '#hooks/useTranslation' ;
1112import useInputState from '#hooks/useInputState' ;
1213import type { CountryOutletContext } from '#utils/outletContext' ;
@@ -43,6 +44,35 @@ export function Component() {
4344 } ,
4445 } ) ;
4546
47+ const {
48+ pending : pendingImminentEventCounts ,
49+ response : imminentEventCountsResponse ,
50+ } = useRiskRequest ( {
51+ apiType : 'risk' ,
52+ url : '/api/v1/country-imminent-counts/' ,
53+ query : {
54+ iso3 : countryResponse ?. iso3 ?. toLowerCase ( ) ,
55+ } ,
56+ } ) ;
57+
58+ const hasImminentEvents = useMemo (
59+ ( ) => {
60+ if ( isNotDefined ( imminentEventCountsResponse ) ) {
61+ return false ;
62+ }
63+
64+ const eventCounts = mapToList (
65+ imminentEventCountsResponse ,
66+ ( value ) => value ,
67+ ) . filter ( isDefined ) . filter (
68+ ( value ) => value > 0 ,
69+ ) ;
70+
71+ return eventCounts . length > 0 ;
72+ } ,
73+ [ imminentEventCountsResponse ] ,
74+ ) ;
75+
4676 // NOTE: we always get 1 child in the response
4777 const riskResponse = countryRiskResponse ?. [ 0 ] ;
4878 const bbox = useMemo (
@@ -52,7 +82,10 @@ export function Component() {
5282
5383 return (
5484 < div className = { styles . countryRiskWatch } >
55- { countryResponse && isDefined ( countryResponse . iso3 ) && (
85+ { pendingImminentEventCounts && (
86+ < BlockLoading />
87+ ) }
88+ { hasImminentEvents && isDefined ( countryResponse ) && isDefined ( countryResponse . iso3 ) && (
5689 < RiskImminentEvents
5790 variant = "country"
5891 iso3 = { countryResponse . iso3 }
0 commit comments