diff options
Diffstat (limited to 'app/javascript/journey_patterns/actions')
| -rw-r--r-- | app/javascript/journey_patterns/actions/index.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index a70a2e6f2..b90908264 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -20,6 +20,12 @@ const actions = { type: "RECEIVE_ERRORS", json }), + receiveRouteCosts: (costs, key, index) => ({ + type: "RECEIVE_ROUTE_COSTS", + costs, + key, + index + }), unavailableServer : () => ({ type: 'UNAVAILABLE_SERVER' }), @@ -213,6 +219,30 @@ const actions = { } }) }, + fetchRouteCosts: (dispatch, key, index) => { + if (actions.routeCostsCache) { + // Dispatch asynchronously to prevent warning when + // this executes during `render()` + requestAnimationFrame(() => { + dispatch(actions.receiveRouteCosts( + actions.routeCostsCache, + key, + index + )) + }) + } else { + fetch(window.routeCostsUrl, { + credentials: 'same-origin', + }).then(response => { + return response.json() + }).then(json => { + let costs = json.costs ? json.costs : {} + actions.routeCostsCache = costs + + dispatch(actions.receiveRouteCosts(costs, key, index)) + }) + } + }, getChecked : (jp) => { return jp.filter((obj) => { return obj.checked |
