Skip to content

Commit 95d8835

Browse files
frozenheliumsamshara
authored andcommitted
Add non-empty source as default in country imminent event
1 parent ebb8465 commit 95d8835

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/components/domain/RiskImminentEvents/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import MeteoSwiss from './MeteoSwiss';
2727
import i18n from './i18n.json';
2828
import styles from './styles.module.css';
2929

30-
type ActiveView = 'pdc' | 'wfpAdam' | 'gdacs' | 'meteoSwiss';
30+
export type ImminentEventSource = 'pdc' | 'wfpAdam' | 'gdacs' | 'meteoSwiss';
3131
type HazardType = components<'read'>['schemas']['HazardTypeEnum'];
3232

3333
type BaseProps = {
3434
className?: string;
3535
title: React.ReactNode;
3636
bbox: LngLatBoundsLike | undefined;
37+
defaultSource?: ImminentEventSource;
3738
}
3839

3940
type Props = BaseProps & ({
@@ -47,8 +48,12 @@ type Props = BaseProps & ({
4748
})
4849

4950
function RiskImminentEvents(props: Props) {
50-
const [activeView, setActiveView] = useState<ActiveView>('pdc');
51-
const { className, ...otherProps } = props;
51+
const {
52+
className,
53+
defaultSource = 'pdc',
54+
...otherProps
55+
} = props;
56+
const [activeView, setActiveView] = useState<ImminentEventSource>(defaultSource);
5257

5358
const strings = useTranslation(i18n);
5459

@@ -75,7 +80,7 @@ function RiskImminentEvents(props: Props) {
7580
[activeView],
7681
);
7782

78-
const handleRadioClick = useCallback((key: ActiveView) => {
83+
const handleRadioClick = useCallback((key: ImminentEventSource) => {
7984
setActiveView(key);
8085
}, []);
8186

src/views/CountryRiskWatch/index.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getBbox from '@turf/bbox';
55

66
import Container from '#components/Container';
77
import Link from '#components/Link';
8-
import RiskImminentEvents from '#components/domain/RiskImminentEvents';
8+
import RiskImminentEvents, { type ImminentEventSource } from '#components/domain/RiskImminentEvents';
99
import HistoricalDataChart from '#components/domain/HistoricalDataChart';
1010
import BlockLoading from '#components/BlockLoading';
1111
import useTranslation from '#hooks/useTranslation';
@@ -73,6 +73,40 @@ export function Component() {
7373
[imminentEventCountsResponse],
7474
);
7575

76+
const defaultImminentEventSource = useMemo<ImminentEventSource | undefined>(
77+
() => {
78+
if (isNotDefined(imminentEventCountsResponse)) {
79+
return undefined;
80+
}
81+
82+
const {
83+
pdc,
84+
adam,
85+
gdacs,
86+
meteoswiss,
87+
} = imminentEventCountsResponse;
88+
89+
if (isDefined(pdc) && pdc > 0) {
90+
return 'pdc';
91+
}
92+
93+
if (isDefined(adam) && adam > 0) {
94+
return 'wfpAdam';
95+
}
96+
97+
if (isDefined(gdacs) && gdacs > 0) {
98+
return 'gdacs';
99+
}
100+
101+
if (isDefined(meteoswiss) && meteoswiss > 0) {
102+
return 'meteoSwiss';
103+
}
104+
105+
return undefined;
106+
},
107+
[imminentEventCountsResponse],
108+
);
109+
76110
// NOTE: we always get 1 child in the response
77111
const riskResponse = countryRiskResponse?.[0];
78112
const bbox = useMemo(
@@ -91,6 +125,7 @@ export function Component() {
91125
iso3={countryResponse.iso3}
92126
title={countryResponse.name}
93127
bbox={bbox}
128+
defaultSource={defaultImminentEventSource}
94129
/>
95130
)}
96131
<Container

0 commit comments

Comments
 (0)