From 3d27d6532ae1a3729b321d482bfa7ed290cd04a2 Mon Sep 17 00:00:00 2001 From: Patrick Cleary Date: Tue, 11 Jul 2023 17:34:43 -0400 Subject: [PATCH] shrink station selector items (#710) * shrink station selector items * revert size of buttons on mobile * Fix bug with station selection * lint * lint --- common/components/inputs/StationSelector.tsx | 27 ++++++++++++++---- .../widgets/StationSelectorWidget.tsx | 28 +++++++++++++++---- common/utils/stations.ts | 9 ++++-- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/common/components/inputs/StationSelector.tsx b/common/components/inputs/StationSelector.tsx index fe2d7cff1..2c08cc0a0 100644 --- a/common/components/inputs/StationSelector.tsx +++ b/common/components/inputs/StationSelector.tsx @@ -34,7 +34,12 @@ export const StationSelector: React.FC = ({ } = useDelimitatedRoute(); const mdBreakpoint = useBreakpoint('md'); const station = type === 'from' ? fromStation : toStation; - const stationOptions = optionsForField(type, lineShort, fromStation, toStation, busRoute); + const stationOptions = optionsForField(type, lineShort, fromStation, busRoute); + const branchLabelWidth = { + 'line-red': 'w-8', + 'line-green': 'w-12', + DEFAULT: 'w-0', + }; return ( {({ open }) => ( @@ -64,7 +69,7 @@ export const StationSelector: React.FC = ({ leaveFrom="transform opacity-100 scale-100" leaveTo="transform opacity-0 scale-95" > - +
{stationOptions?.map((station, stationIndex) => ( = ({ } className={({ active, selected, disabled }) => classNames( - 'relative select-none items-center px-4 py-2', + 'relative select-none items-center px-4 py-2 lg:py-1 lg:text-sm', active ? lineColorLightBackground[line ?? 'DEFAULT'] : 'text-gray-900', selected ? `bg-opacity-20 font-semibold ${lineColorBackground[line ?? 'DEFAULT']}` @@ -86,8 +91,20 @@ export const StationSelector: React.FC = ({ } value={station} > -
- {station.stop_name} +
+
+
+ {station.branches?.map((branch) => ( +

{branch}

+ ))} +
+ {station.stop_name} +
{station.enclosed_bike_parking ? ( = ({ li updateQueryParams({ from: fromStopIds?.[0], to: toStopIds?.[0] }); }, [fromStation, toStation, updateQueryParams]); - const updateStations = (action: 'to' | 'from' | 'swap', stationId?: Station) => { + const updateStations = (action: 'to' | 'from' | 'swap', newStation?: Station) => { switch (action) { case 'to': updateQueryParams( { - to: stopIdsForStations(fromStation, stationId).toStopIds?.[0], + to: stopIdsForStations(fromStation, newStation).toStopIds?.[0], }, undefined, false ); break; - case 'from': + case 'from': { + if (newStation?.branches?.some((branch) => toStation?.branches?.includes(branch))) { + updateQueryParams( + { + from: stopIdsForStations(newStation, toStation).fromStopIds?.[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: stopIdsForStations(stationId, toStation).fromStopIds?.[0], + from: stationIds?.fromStopIds?.[0], + to: stationIds?.toStopIds?.[0], }, undefined, false ); break; + } case 'swap': { const { fromStopIds, toStopIds } = stopIdsForStations(fromStation, toStation); updateQueryParams({ from: toStopIds?.[0], to: fromStopIds?.[0] }, undefined, false); @@ -75,7 +91,7 @@ export const StationSelectorWidget: React.FC = ({ li type={'from'} fromStation={fromStation} toStation={toStation} - setStation={(stationId) => updateStations('from', stationId)} + setStation={(newStation) => updateStations('from', newStation)} />
@@ -84,7 +100,7 @@ export const StationSelectorWidget: React.FC = ({ li type={'to'} fromStation={fromStation} toStation={toStation} - setStation={(stationId) => updateStations('to', stationId)} + setStation={(newStation) => updateStations('to', newStation)} />