From 5d49cb6fe7065e11a1229f0a828c0f6474baa0fe Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Tue, 17 Dec 2024 14:52:01 -0800 Subject: [PATCH] clean up selection and onSelectionChange --- lib/interviewer/containers/Interfaces/Geospatial.tsx | 4 ++-- lib/interviewer/hooks/useMapbox.ts | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/interviewer/containers/Interfaces/Geospatial.tsx b/lib/interviewer/containers/Interfaces/Geospatial.tsx index 4ba339d5..e8fdc732 100644 --- a/lib/interviewer/containers/Interfaces/Geospatial.tsx +++ b/lib/interviewer/containers/Interfaces/Geospatial.tsx @@ -106,13 +106,13 @@ export default function GeospatialInterface({ tokenId, getAssetUrl, initialSelectionValue, - onSelectionChange: (selection: unknown) => { + onSelectionChange: (value: string) => { if (currentPrompt && stageNodes[navState.activeIndex]) { updateNode( stageNodes[navState.activeIndex][entityPrimaryKeyProperty], {}, { - [currentPrompt.variable]: selection, + [currentPrompt.variable]: value, }, ); } diff --git a/lib/interviewer/hooks/useMapbox.ts b/lib/interviewer/hooks/useMapbox.ts index bafd1814..451d9c3e 100644 --- a/lib/interviewer/hooks/useMapbox.ts +++ b/lib/interviewer/hooks/useMapbox.ts @@ -20,7 +20,7 @@ type UseMapboxProps = { tokenId: string; getAssetUrl: (url: string) => string; initialSelectionValue?: string; - onSelectionChange: (value: string | null) => void; + onSelectionChange: (value: string) => void; }; const useMapboxToken = (tokenId: string) => { @@ -206,17 +206,19 @@ export const useMapbox = ({ const feature = e.features[0]; const propToSelect = selectionLayer.filter; - const selected = feature?.properties - ? feature.properties[propToSelect] + const selected: string | null = feature?.properties + ? (feature.properties[propToSelect] as string) : null; - onSelectionChange(selected); + if (selected !== null) { + onSelectionChange(selected); + } if (selectionLayer && mapInstance) { mapInstance.setFilter(selectionLayer.id, [ '==', selectionLayer.filter, - selected, + selected ?? '', ]); } };