diff --git a/common/components/widgets/StationSelectorWidget.tsx b/common/components/widgets/StationSelectorWidget.tsx index ac2e18c7..fb1bb1ef 100644 --- a/common/components/widgets/StationSelectorWidget.tsx +++ b/common/components/widgets/StationSelectorWidget.tsx @@ -26,10 +26,9 @@ export const StationSelectorWidget: React.FC = ({ 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] }); diff --git a/common/utils/stations.ts b/common/utils/stations.ts index b19aa54d..8e0a9222 100644 --- a/common/utils/stations.ts +++ b/common/utils/stations.ts @@ -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]; }; diff --git a/modules/tripexplorer/TripExplorer.tsx b/modules/tripexplorer/TripExplorer.tsx index e5c0071b..8b313548 100644 --- a/modules/tripexplorer/TripExplorer.tsx +++ b/modules/tripexplorer/TripExplorer.tsx @@ -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 }; });