From fd6dafb08eba446dfb7a41a11ab385fae2221001 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:54:40 -0600 Subject: [PATCH 1/2] Only call stopTimes if we don't already have the data --- lib/actions/apiV2.js | 7 +++++++ lib/components/viewers/stop-schedule-viewer.tsx | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index e7deb84e3..626243897 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -505,6 +505,13 @@ export const fetchNearby = (position, radius, currentServiceWeek) => { export const findStopTimesForStop = (params) => function (dispatch, getState) { + // If the stop is already in the store, don't fetch it again, unless we are forcing a refetch + if ( + !params.forceFetch && + getState().otp.transitIndex.stops[params.stopId] + ) { + return + } dispatch(fetchingStopTimesForStop(params)) const { date, stopId } = params const timeZone = getState().otp.config.homeTimezone diff --git a/lib/components/viewers/stop-schedule-viewer.tsx b/lib/components/viewers/stop-schedule-viewer.tsx index 51f85c967..8b62234c8 100644 --- a/lib/components/viewers/stop-schedule-viewer.tsx +++ b/lib/components/viewers/stop-schedule-viewer.tsx @@ -33,7 +33,11 @@ import TimezoneWarning from './timezone-warning' interface Props { calendarMax: string calendarMin: string - findStopTimesForStop: (arg: { date: string; stopId: string }) => void + findStopTimesForStop: (arg: { + date: string + forceFetch?: boolean + stopId: string + }) => void hideBackButton?: boolean homeTimezone: string intl: IntlShape @@ -137,7 +141,7 @@ class StopScheduleViewer extends Component { _findStopTimesForDate = (date: string) => { const { findStopTimesForStop, stopId } = this.props if (stopId) { - findStopTimesForStop({ date, stopId }) + findStopTimesForStop({ date, forceFetch: true, stopId }) } } From 7e30272c8f0a0cc575ce089ea7ee1f098bc78d16 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:22:26 -0600 Subject: [PATCH 2/2] remove unnecessary brackets in return --- lib/actions/apiV2.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 626243897..9438d5e3d 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -506,12 +506,9 @@ export const fetchNearby = (position, radius, currentServiceWeek) => { export const findStopTimesForStop = (params) => function (dispatch, getState) { // If the stop is already in the store, don't fetch it again, unless we are forcing a refetch - if ( - !params.forceFetch && - getState().otp.transitIndex.stops[params.stopId] - ) { + if (!params.forceFetch && getState().otp.transitIndex.stops[params.stopId]) return - } + dispatch(fetchingStopTimesForStop(params)) const { date, stopId } = params const timeZone = getState().otp.config.homeTimezone