diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index e7deb84e3..9438d5e3d 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -505,6 +505,10 @@ 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 }) } }