Skip to content

Commit

Permalink
feat: handle hochmontan altitudinal zones for locate function
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Apr 9, 2020
1 parent 3580a80 commit b114ac8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/store/enhancers/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const projectionActionTypes = [

export const hochmontanAltitudinalZones = ['81', '82', '83'];

const runProjection = (location, targetAltitudinalZone) => {
const runProject = (location, targetAltitudinalZone) => {
let newTargetAltitudinalZone = targetAltitudinalZone;
let { altitudinalZone, silverFirArea } = location;
if (hochmontanAltitudinalZones.includes(targetAltitudinalZone)) {
Expand All @@ -34,6 +34,16 @@ const runProjection = (location, targetAltitudinalZone) => {
return project(newLocation, newTargetAltitudinalZone);
};

const runLocate = (location) => {
let { altitudinalZone, silverFirArea } = location;
if (hochmontanAltitudinalZones.includes(altitudinalZone)) {
silverFirArea = altitudinalZone.slice(1);
altitudinalZone = '80';
}
const newLocation = { ...location, altitudinalZone, silverFirArea };
return locate(newLocation);
};

const projection = (store) => (next) => (action) => {
const result = next(action);
if (projectionActionTypes.includes(action.type)) {
Expand All @@ -49,7 +59,7 @@ const projection = (store) => (next) => (action) => {
store.dispatch(setLocation(location));

try {
const locateResult = locate(location);
const locateResult = runLocate(location);
store.dispatch(setLocationResult(locateResult));
} catch (error) {
console.log('Locate error: ', error);
Expand All @@ -62,11 +72,11 @@ const projection = (store) => (next) => (action) => {
targetAltitudinalZoneModerate: targetAZModerate,
targetAltitudinalZoneExtreme: targetAZExtreme,
} = mapLocation;
projectionResult.moderate = runProjection(location, targetAZModerate);
projectionResult.extreme = runProjection(location, targetAZExtreme);
projectionResult.moderate = runProject(location, targetAZModerate);
projectionResult.extreme = runProject(location, targetAZExtreme);
} else {
const { targetAltitudinalZone: targetAZForm } = formLocation;
projectionResult.form = runProjection(location, targetAZForm);
projectionResult.form = runProject(location, targetAZForm);
}
store.dispatch(setProjectionResult(projectionResult));
} catch (error) {
Expand Down

0 comments on commit b114ac8

Please # to comment.