Skip to content

Commit

Permalink
Merge branch 'main' into add-aggr-bunched-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte authored Feb 20, 2025
2 parents c161f8b + 92a4e39 commit dcb1fde
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions common/components/widgets/StationSelectorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ export const StationSelectorWidget: React.FC<StationSelectorWidgetProps> = ({ li
const {
query: { from, to },
} = useDelimitatedRoute();

const stations = optionsStation(lineShort, busRoute);
const toStation = to ? getParentStationForStopId(to) : stations?.[stations.length - 2];
const fromStation = from ? getParentStationForStopId(from) : stations?.[1];
const toStation = to ? getParentStationForStopId(to, lineShort) : stations?.[stations.length - 2];
const fromStation = from ? getParentStationForStopId(from, lineShort) : stations?.[1];
React.useEffect(() => {
const { fromStopIds, toStopIds } = stopIdsForStations(fromStation, toStation);
updateQueryParams({ from: fromStopIds?.[0], to: toStopIds?.[0] });
Expand Down
15 changes: 14 additions & 1 deletion common/utils/stations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,20 @@ export const getStationById = (stationStopId: string) => {
return stationIndex[stationStopId];
};

export const getParentStationForStopId = (stopId: string) => {
/** Given a stop id, return the full station it belongs to
* We need the line to get the correct station when lines share ids (Ex: Ashmont)
*/
export const getParentStationForStopId = (stopId: string, line?: LineShort) => {
if (line && line !== 'Bus' && line !== 'Commuter Rail') {
const station = stations[line].stations.find(
(station: Station) =>
station.stops['0'].includes(stopId) || station.stops['1'].includes(stopId)
);
if (station) {
return station;
}
}

return parentStationIndex[stopId];
};

Expand Down
4 changes: 2 additions & 2 deletions modules/tripexplorer/TripExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const TripExplorer = () => {
} = useDelimitatedRoute();
const { data: alerts } = useHistoricalAlertsData(date, lineShort, busRoute);

const fromStation = from ? getParentStationForStopId(from) : undefined;
const toStation = to ? getParentStationForStopId(to) : undefined;
const fromStation = from ? getParentStationForStopId(from, lineShort) : undefined;
const toStation = to ? getParentStationForStopId(to, lineShort) : undefined;
const alertsForModal = alerts?.filter(findMatch).map((alert) => {
return { ...alert, applied: false };
});
Expand Down

0 comments on commit dcb1fde

Please sign in to comment.