Skip to content

Commit

Permalink
fix(timetable): refetch trip counts on trip add/delete
Browse files Browse the repository at this point in the history
fixes #143
  • Loading branch information
landonreed committed May 13, 2018
1 parent f461421 commit 93ac6bb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/editor/actions/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
})
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
})
}
}
Expand Down

0 comments on commit 93ac6bb

Please # to comment.