Skip to content

Commit 3ce3e45

Browse files
frozenheliumsamshara
authored andcommitted
Hide imminent events in country if there are no events from any source
1 parent 0c4d98a commit 3ce3e45

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/views/CountryRiskWatch/index.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useMemo } from 'react';
22
import { useParams, useOutletContext } from 'react-router-dom';
3-
import { isDefined } from '@togglecorp/fujs';
3+
import { isDefined, isNotDefined, mapToList } from '@togglecorp/fujs';
44
import getBbox from '@turf/bbox';
55

66
import Container from '#components/Container';
77
import Link from '#components/Link';
88
import RiskImminentEvents from '#components/domain/RiskImminentEvents';
99
import HistoricalDataChart from '#components/domain/HistoricalDataChart';
10+
import BlockLoading from '#components/BlockLoading';
1011
import useTranslation from '#hooks/useTranslation';
1112
import useInputState from '#hooks/useInputState';
1213
import 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

Comments
 (0)