From 87e75a60b9201a8db2a71ea3267e1c374b9065ba Mon Sep 17 00:00:00 2001 From: frozenhelium Date: Thu, 17 Oct 2024 14:16:52 +0545 Subject: [PATCH 1/4] Create a GlobalMap component - Use GlobalMap in the ActiveOperationMap --- .../domain/ActiveOperationMap/index.tsx | 65 ++--- .../ActiveOperationMap/styles.module.css | 3 +- app/src/components/domain/BaseMap/index.tsx | 25 +- app/src/components/domain/GlobalMap/index.tsx | 238 ++++++++++++++++++ .../domain/RiskImminentEventMap/index.tsx | 6 +- app/src/utils/constants.ts | 2 +- 6 files changed, 270 insertions(+), 69 deletions(-) create mode 100644 app/src/components/domain/GlobalMap/index.tsx diff --git a/app/src/components/domain/ActiveOperationMap/index.tsx b/app/src/components/domain/ActiveOperationMap/index.tsx index 15903383b..7a19fc5ee 100644 --- a/app/src/components/domain/ActiveOperationMap/index.tsx +++ b/app/src/components/domain/ActiveOperationMap/index.tsx @@ -32,9 +32,8 @@ import { MapLayer, MapSource, } from '@togglecorp/re-map'; -import type { LngLatBoundsLike } from 'mapbox-gl'; +import { type LngLatBoundsLike } from 'mapbox-gl'; -import BaseMap from '#components/domain/BaseMap'; import DisasterTypeSelectInput from '#components/domain/DisasterTypeSelectInput'; import DistrictSearchMultiSelectInput, { type DistrictItem } from '#components/domain/DistrictSearchMultiSelectInput'; import Link from '#components/Link'; @@ -48,13 +47,13 @@ import { DEFAULT_MAP_PADDING, DURATION_MAP_ZOOM, } from '#utils/constants'; -import { adminFillLayerOptions } from '#utils/map'; import type { GoApiResponse, GoApiUrlQuery, } from '#utils/restRequest'; import { useRequest } from '#utils/restRequest'; +import GlobalMap, { AdminZeroFeatureProperties } from '../GlobalMap'; import { APPEAL_TYPE_DREF, APPEAL_TYPE_EAP, @@ -87,24 +86,8 @@ const sourceOptions: mapboxgl.GeoJSONSourceRaw = { type: 'geojson', }; -interface CountryProperties { - country_id: number; - disputed: boolean; - fdrs: string; - independent: boolean; - is_deprecated: boolean; - iso: string; - iso3: string; - name: string; - name_ar: string; - name_es: string; - name_fr: string; - record_type: number; - region_id: number; -} - interface ClickedPoint { - feature: GeoJSON.Feature; + featureProperties: AdminZeroFeatureProperties; lngLat: mapboxgl.LngLatLike; } @@ -188,8 +171,8 @@ function ActiveOperationMap(props: Props) { ); const [ - clickedPointProperties, - setClickedPointProperties, + clickedPoint, + setClickedPoint, ] = useState(); const [scaleBy, setScaleBy] = useInputState('peopleTargeted'); @@ -348,29 +331,30 @@ function ActiveOperationMap(props: Props) { ); const handleCountryClick = useCallback(( - feature: mapboxgl.MapboxGeoJSONFeature, + featureProperties: AdminZeroFeatureProperties, lngLat: mapboxgl.LngLatLike, ) => { - setClickedPointProperties({ - feature: feature as unknown as ClickedPoint['feature'], + setClickedPoint({ + featureProperties, lngLat, }); - return false; + + return true; }, []); const handlePointClose = useCallback( () => { - setClickedPointProperties(undefined); + setClickedPoint(undefined); }, - [setClickedPointProperties], + [setClickedPoint], ); const handleClearFiltersButtonclick = useCallback(() => { setFilter({}); }, [setFilter]); - const popupDetails = clickedPointProperties - ? countryGroupedAppeal[clickedPointProperties.feature.properties.iso3] + const popupDetails = clickedPoint + ? countryGroupedAppeal[clickedPoint.featureProperties.iso3] : undefined; const [districtOptions, setDistrictOptions] = useState(); @@ -447,15 +431,8 @@ function ActiveOperationMap(props: Props) { )} > - - )} + - {clickedPointProperties?.lngLat && ( + {clickedPoint?.lngLat && ( - {clickedPointProperties.feature.properties.name} + {clickedPoint.featureProperties.name} )} childrenContainerClassName={styles.popupContent} @@ -560,7 +537,7 @@ function ActiveOperationMap(props: Props) { padding={DEFAULT_MAP_PADDING} /> )} - + {onPresentationModeButtonClick && !presentationMode && (