From eb0b1edb54166366312600a5032e3d862bb635aa Mon Sep 17 00:00:00 2001 From: devinleighsmith Date: Wed, 28 Jun 2023 16:32:17 -0700 Subject: [PATCH] correct try/catch location. --- .../components/maps/hooks/useMapSearch.tsx | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/source/frontend/src/components/maps/hooks/useMapSearch.tsx b/source/frontend/src/components/maps/hooks/useMapSearch.tsx index 8c1b5cdd02..3b6860e8ac 100644 --- a/source/frontend/src/components/maps/hooks/useMapSearch.tsx +++ b/source/frontend/src/components/maps/hooks/useMapSearch.tsx @@ -51,8 +51,31 @@ export const useMapSearch = () => { tileData = pimsProperties.features.length ? pimsProperties : parcel; } else { let task1, task2, task3; + + task1 = loadProperties(filter); + + if (filter?.PIN) { + task2 = parcelsService.findByPin(filter?.PIN); + } + if (filter?.PID) { + task3 = parcelsService.findByPid(filter?.PID); + } + try { - task1 = loadProperties(filter); + const [pidPinInventoryData, pinNonInventoryData, pidNonInventoryData] = await Promise.all( + [task1, task2, task3], + ); + + tileData = pidPinInventoryData?.features?.length + ? pidPinInventoryData + : ({ + type: 'FeatureCollection', + features: [ + ...(pinNonInventoryData?.features || []), + ...(pidNonInventoryData?.features || []), + ], + bbox: pinNonInventoryData?.bbox || pidNonInventoryData?.bbox, + } as FeatureCollection); } catch (err) { setModalContent({ title: 'Unable to connect to PIMS Inventory', @@ -69,30 +92,6 @@ export const useMapSearch = () => { }); setDisplayModal(true); } - - if (filter?.PIN) { - task2 = parcelsService.findByPin(filter?.PIN); - } - if (filter?.PID) { - task3 = parcelsService.findByPid(filter?.PID); - } - - const [pidPinInventoryData, pinNonInventoryData, pidNonInventoryData] = await Promise.all([ - task1, - task2, - task3, - ]); - - tileData = pidPinInventoryData?.features?.length - ? pidPinInventoryData - : ({ - type: 'FeatureCollection', - features: [ - ...(pinNonInventoryData?.features || []), - ...(pidNonInventoryData?.features || []), - ], - bbox: pinNonInventoryData?.bbox || pidNonInventoryData?.bbox, - } as FeatureCollection); } if (tileData) { const validFeatures = tileData.features.filter(feature => !!feature?.geometry);