diff --git a/lib/editor/actions/trip.js b/lib/editor/actions/trip.js index bb38421c4..229f3e1c6 100644 --- a/lib/editor/actions/trip.js +++ b/lib/editor/actions/trip.js @@ -26,7 +26,7 @@ export const addNewTrip = createAction('ADD_NEW_TRIP') export const removeTrips = createAction('REMOVE_TRIPS') // REST actions -export function fetchTripsForCalendar (feedId, pattern, calendarId) { +export function fetchTripsForCalendar (feedId, pattern, calendarId, fetchCounts = false) { return function (dispatch, getState) { const namespace = getEditorNamespace(feedId, getState()) // This fetches patterns on the pattern_id field (rather than ID) because @@ -77,6 +77,9 @@ export function fetchTripsForCalendar (feedId, pattern, calendarId) { errorMessage: 'Could not fetch trips for pattern' })) .then(data => dispatch(receiveTripsForCalendar({trips: data.feed.patterns[0].trips, pattern}))) + .then(() => { + fetchCounts && dispatch(fetchCalendarTripCountsForPattern(feedId, pattern.patternId)) + }) } } @@ -106,14 +109,12 @@ export function saveTripsForCalendar (feedId, pattern, calendarId, trips) { }) })) .then(trips => { - // console.log(trips) if (errorCount) { dispatch(setErrorMessage({message: `Unknown error encountered while saving trips. Could not save ${errorCount} trips`})) } - dispatch(fetchTripsForCalendar(feedId, pattern, calendarId)) + dispatch(fetchTripsForCalendar(feedId, pattern, calendarId, true)) return errorIndexes }) - // return result } } @@ -163,7 +164,7 @@ export function saveMultipleTripsForCalendar (feedId, pattern, calendarId, trips if (errorCount) { dispatch(setErrorMessage({message: `Unknown error encountered while saving trips. Could not save ${errorCount} trips`})) } - dispatch(fetchTripsForCalendar(feedId, pattern, calendarId)) + dispatch(fetchTripsForCalendar(feedId, pattern, calendarId, true)) return errorIndexes }) // return result @@ -191,7 +192,7 @@ export function deleteTripsForCalendar (feedId, pattern, calendarId, trips) { if (errorCount) { dispatch(setErrorMessage({message: `Unknown error encountered while deleting trips. Could not delete ${errorCount} trips`})) } - dispatch(fetchTripsForCalendar(feedId, pattern, calendarId)) + dispatch(fetchTripsForCalendar(feedId, pattern, calendarId, true)) }) } }