From e33aa0199b09a26e6d3f7d973861d6e6bd070cf7 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Thu, 5 Sep 2024 15:47:05 -0700 Subject: [PATCH 1/3] add option to use arrival time in nearby view --- example-config.yml | 2 ++ lib/components/viewers/stop-time-cell.tsx | 10 +++++++--- lib/util/config-types.ts | 1 + lib/util/viewer.js | 16 ++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/example-config.yml b/example-config.yml index d132b835e..c24e1265d 100644 --- a/example-config.yml +++ b/example-config.yml @@ -677,6 +677,8 @@ itinerary: # sessionTimeoutSeconds: 180 # nearbyView: +### Setting to use arrival time instead of departure time in the nearby view. +# useArrivalTime: true ### Setting to hide stops with no depatures in the nearby view. # hideEmptyStops: true ### What radius should the nearby query get results within? (in meters) diff --git a/lib/components/viewers/stop-time-cell.tsx b/lib/components/viewers/stop-time-cell.tsx index d1867c3c2..fb103897d 100644 --- a/lib/components/viewers/stop-time-cell.tsx +++ b/lib/components/viewers/stop-time-cell.tsx @@ -36,6 +36,8 @@ type Props = { onlyShowCountdownForRealtime?: boolean /** A stopTime object as received from a transit index API */ stopTime: Time + /** Whether to use arrival time instead of departure time */ + useArrivalTime?: boolean } /** @@ -46,7 +48,8 @@ type Props = { const StopTimeCell = ({ homeTimezone = getUserTimezone(), onlyShowCountdownForRealtime, - stopTime + stopTime, + useArrivalTime }: Props): JSX.Element => { const intl = useIntl() @@ -72,7 +75,7 @@ const StopTimeCell = ({ // Determine whether to show departure as countdown (e.g. "5 min") or as HH:mm // time, using realtime updates if available. const secondsUntilDeparture = Math.round( - getSecondsUntilDeparture(stopTime, false) + getSecondsUntilDeparture(stopTime, false, useArrivalTime) ) // Determine if vehicle arrives after midnight in order to advance the day of // the week when showing arrival time/day. @@ -151,7 +154,8 @@ const StopTimeCell = ({ const mapStateToProps = (state: AppReduxState) => { return { onlyShowCountdownForRealtime: - state.otp.config?.itinerary?.onlyShowCountdownForRealtime || false + state.otp.config?.itinerary?.onlyShowCountdownForRealtime || false, + useArrivalTime: state.otp.config?.nearbyView?.useArrivalTime || false } } diff --git a/lib/util/config-types.ts b/lib/util/config-types.ts index 18e27ca37..a11c51d50 100644 --- a/lib/util/config-types.ts +++ b/lib/util/config-types.ts @@ -73,6 +73,7 @@ export type NearbyViewConfig = { hideEmptyStops?: boolean radius?: number showShadowDotOnMapDrag?: boolean + useArrivalTime?: boolean useRouteViewSort?: boolean } diff --git a/lib/util/viewer.js b/lib/util/viewer.js index 9aabdacc2..20e9cbbbb 100644 --- a/lib/util/viewer.js +++ b/lib/util/viewer.js @@ -13,12 +13,20 @@ import { isBlank } from './ui' * Computes the seconds until departure for a given stop time, * based either on the scheduled or the realtime departure time. */ -export function getSecondsUntilDeparture(stopTime, useSchedule) { - const departureTime = useSchedule - ? stopTime.scheduledDeparture +export function getSecondsUntilDeparture( + stopTime, + useSchedule, + useArrivalTime +) { + const time = useSchedule + ? useArrivalTime + ? stopTime.scheduledArrival + : stopTime.scheduledDeparture + : useArrivalTime + ? stopTime.realtimeArrival : stopTime.realtimeDeparture - return departureTime + stopTime.serviceDay - Date.now() / 1000 + return time + stopTime.serviceDay - Date.now() / 1000 } export function getRouteIdForPattern(pattern) { From 53c75022828d3c9f46f47f02b20ee29cf48e6382 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Thu, 5 Sep 2024 15:52:19 -0700 Subject: [PATCH 2/3] update snapshots --- .../viewers/__snapshots__/nearby-view.js.snap | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap index b20164dd6..b7bd84dc0 100644 --- a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap +++ b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap @@ -11860,6 +11860,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
viewers > nearby view renders proper scooter dates 1`] = ` }, } } + useArrivalTime={false} >
Date: Thu, 19 Sep 2024 13:35:42 -0700 Subject: [PATCH 3/3] clean up long ternary --- lib/util/viewer.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/util/viewer.js b/lib/util/viewer.js index 20e9cbbbb..faa994560 100644 --- a/lib/util/viewer.js +++ b/lib/util/viewer.js @@ -18,13 +18,16 @@ export function getSecondsUntilDeparture( useSchedule, useArrivalTime ) { - const time = useSchedule - ? useArrivalTime + let time + if (useSchedule) { + time = useArrivalTime ? stopTime.scheduledArrival : stopTime.scheduledDeparture - : useArrivalTime - ? stopTime.realtimeArrival - : stopTime.realtimeDeparture + } else { + time = useArrivalTime + ? stopTime.realtimeArrival + : stopTime.realtimeDeparture + } return time + stopTime.serviceDay - Date.now() / 1000 }