From a80fbe660f3a2da2980f39d6faf672fa15aff1c4 Mon Sep 17 00:00:00 2001 From: Patrick Cleary Date: Wed, 12 Jul 2023 10:42:19 -0400 Subject: [PATCH] Fix bug with selecting from stations. (#740) --- .../widgets/StationSelectorWidget.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/common/components/widgets/StationSelectorWidget.tsx b/common/components/widgets/StationSelectorWidget.tsx index 41f035cf6..2bbc143d2 100644 --- a/common/components/widgets/StationSelectorWidget.tsx +++ b/common/components/widgets/StationSelectorWidget.tsx @@ -47,23 +47,27 @@ export const StationSelectorWidget: React.FC = ({ li ); break; case 'from': { - if (newStation?.branches?.some((branch) => toStation?.branches?.includes(branch))) { + if ( + newStation && + newStation.branches && + !newStation?.branches?.some((branch) => toStation?.branches?.includes(branch)) + ) { + // If `from` station is on a separate branch, set the `to` station to gov center for GL and Park for RL. + const newToStation = getStationForInvalidFromSelection(line); + const stationIds = stopIdsForStations(newStation, newToStation); updateQueryParams( { - from: stopIdsForStations(newStation, toStation).fromStopIds?.[0], + from: stationIds?.fromStopIds?.[0], + to: stationIds?.toStopIds?.[0], }, undefined, false ); break; } - // If `from` station is on a separate branch, set the `to` station to gov center for GL and Park for RL. - const newToStation = getStationForInvalidFromSelection(line); - const stationIds = stopIdsForStations(newStation, newToStation); updateQueryParams( { - from: stationIds?.fromStopIds?.[0], - to: stationIds?.toStopIds?.[0], + from: stopIdsForStations(newStation, toStation).fromStopIds?.[0], }, undefined, false