Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call stopTimes if we don't already have the data #1308

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we one-line this if eslint lets us? Getting rid of the brackets might help.

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
Loading