Skip to content

Commit

Permalink
Honor limited connecting modes when location dragged
Browse files Browse the repository at this point in the history
there were a few cases where i overlooked passing this thru.
  • Loading branch information
graue committed Jan 25, 2024
1 parent a34a8e1 commit 12edae7
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/features/routeParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,6 @@ export function locationsSubmitted() {
connectingModes,
} = getState().routeParams;

const blockRouteTypes = [];
for (const modeCategory of Object.values(TransitModes.CATEGORIES)) {
if (!connectingModes.includes(modeCategory)) {
for (const modeInCategory of TransitModes.CATEGORY_TO_MODES[
modeCategory
]) {
blockRouteTypes.push(modeInCategory);
}
}
}

const hydrate = async function hydrate(text, location, startOrEnd) {
// Decide whether to use the text or location:
let useLocation = false;
Expand Down Expand Up @@ -329,7 +318,7 @@ export function locationsSubmitted() {
resultingEndLocation.point.geometry.coordinates,
arriveBy,
initialTime,
blockRouteTypes,
_computeBlockRouteTypes(connectingModes),
)(dispatch, getState);
}
};
Expand All @@ -344,20 +333,23 @@ export function locationDragged(startOrEnd, coords) {
});

// If we have a location for the other point, fetch a route.
let { start, end, arriveBy, initialTime } = getState().routeParams;
let { start, end, arriveBy, initialTime, connectingModes } =
getState().routeParams;
if (startOrEnd === 'start' && end?.point?.geometry.coordinates) {
await fetchRoute(
coords,
end.point.geometry.coordinates,
arriveBy,
initialTime,
_computeBlockRouteTypes(connectingModes),
)(dispatch, getState);
} else if (startOrEnd === 'end' && start?.point?.geometry.coordinates) {
await fetchRoute(
start.point.geometry.coordinates,
coords,
arriveBy,
initialTime,
_computeBlockRouteTypes(connectingModes),
)(dispatch, getState);
}
};
Expand All @@ -374,20 +366,23 @@ export function locationSelectedOnMap(startOrEnd, coords) {
});

// If we have a location for the other point, fetch a route.
let { start, end, arriveBy, initialTime } = getState().routeParams;
let { start, end, arriveBy, initialTime, connectingModes } =
getState().routeParams;
if (startOrEnd === 'start' && end?.point?.geometry.coordinates) {
await fetchRoute(
coords,
end.point.geometry.coordinates,
arriveBy,
initialTime,
_computeBlockRouteTypes(connectingModes),
)(dispatch, getState);
} else if (startOrEnd === 'end' && start?.point?.geometry.coordinates) {
await fetchRoute(
start.point.geometry.coordinates,
coords,
arriveBy,
initialTime,
_computeBlockRouteTypes(connectingModes),
)(dispatch, getState);
}
};
Expand Down Expand Up @@ -521,3 +516,17 @@ export function changeConnectingModes(newConnectingModes) {
dispatch(locationsSubmitted());
};
}

function _computeBlockRouteTypes(connectingModes) {
const blockRouteTypes = [];
for (const modeCategory of Object.values(TransitModes.CATEGORIES)) {
if (!connectingModes.includes(modeCategory)) {
for (const modeInCategory of TransitModes.CATEGORY_TO_MODES[
modeCategory
]) {
blockRouteTypes.push(modeInCategory);
}
}
}
return blockRouteTypes;
}

0 comments on commit 12edae7

Please sign in to comment.