Skip to content

Commit

Permalink
Only call stopTimes if we don't already have the data
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-corson-ibigroup committed Nov 25, 2024
1 parent a9ce15f commit fd6dafb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/components/viewers/stop-schedule-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,7 +141,7 @@ class StopScheduleViewer extends Component<Props, State> {
_findStopTimesForDate = (date: string) => {
const { findStopTimesForStop, stopId } = this.props
if (stopId) {
findStopTimesForStop({ date, stopId })
findStopTimesForStop({ date, forceFetch: true, stopId })
}
}

Expand Down

0 comments on commit fd6dafb

Please sign in to comment.