diff --git a/layouts/map/actions.js b/layouts/map/actions.js index 58c4e891da..52416cda14 100644 --- a/layouts/map/actions.js +++ b/layouts/map/actions.js @@ -12,55 +12,56 @@ export const setMainMapSettings = createAction('setMainMapSettings'); * @see https://redux.js.org/usage/writing-logic-thunks for implementation details * @param {string} setMainMapAnalysisView - Action name * @param {function} - Arrow function - * @param {object} data - area data (adm_level, gid_0, country, ...) - * @param {object} layer - political boundaries obejct from Layer API + * @param {object} data - area data (adm_level, gid_0, country, ...) + * @param {object} layer - political boundaries obejct from Layer API */ export const setMainMapAnalysisView = createThunkAction( 'setMainMapAnalysisView', - ({ data, layer }) => () => { - const { cartodb_id, wdpaid } = data || {}; - const { analysisEndpoint, tableName } = layer || {}; - const { query, pushQuery } = useRouter(); - const { map, mainMap } = query || {}; + ({ data, layer }) => + () => { + const { cartodb_id, wdpaid } = data || {}; + const { analysisEndpoint, tableName } = layer || {}; + const { query, pushQuery } = useRouter(); + const { map, mainMap } = query || {}; - let payload = {}; - if (data) { - if (analysisEndpoint === 'admin') { - payload = { - type: 'country', - ...getGadmLocationByLevel(data), - }; - } else if (analysisEndpoint === 'wdpa' && (cartodb_id || wdpaid)) { - payload = { - type: analysisEndpoint, - adm0: wdpaid || cartodb_id, - }; - } else if (cartodb_id && tableName) { - payload = { - type: 'use', - adm0: tableName, - adm1: cartodb_id, - }; + let payload = {}; + if (data) { + if (analysisEndpoint === 'admin') { + payload = { + type: 'country', + ...getGadmLocationByLevel(data), + }; + } else if (analysisEndpoint === 'wdpa' && wdpaid) { + payload = { + type: analysisEndpoint, + adm0: wdpaid, + }; + } else if (cartodb_id && tableName) { + payload = { + type: 'use', + adm0: tableName, + adm1: cartodb_id, + }; + } } - } - if (payload && payload.adm0) { - pushQuery({ - pathname: `/map/${compact(Object.values(payload))?.join('/')}/`, - query: { - ...query, - map: { - ...map, - canBound: true, - }, - mainMap: { - ...mainMap, - showAnalysis: true, + if (payload && payload.adm0) { + pushQuery({ + pathname: `/map/${compact(Object.values(payload))?.join('/')}/`, + query: { + ...query, + map: { + ...map, + canBound: true, + }, + mainMap: { + ...mainMap, + showAnalysis: true, + }, }, - }, - }); + }); + } } - } ); export const setDrawnGeostore = createThunkAction(