2016-11-10 14:26:24 +01:00
|
|
|
import api from '../data/history-api';
|
|
|
|
|
2017-06-29 08:36:10 +02:00
|
|
|
export const RECEIVE_HISTORY = 'RECEIVE_HISTORY';
|
|
|
|
export const ERROR_RECEIVE_HISTORY = 'ERROR_RECEIVE_HISTORY';
|
2016-11-10 14:26:24 +01:00
|
|
|
|
2017-06-29 08:36:10 +02:00
|
|
|
export const RECEIVE_HISTORY_FOR_TOGGLE = 'RECEIVE_HISTORY_FOR_TOGGLE';
|
2016-12-05 17:59:16 +01:00
|
|
|
|
2016-11-10 14:26:24 +01:00
|
|
|
const receiveHistory = (json) => ({
|
|
|
|
type: RECEIVE_HISTORY,
|
|
|
|
value: json.events,
|
|
|
|
});
|
|
|
|
|
2016-12-05 17:59:16 +01:00
|
|
|
const receiveHistoryforToggle = (json) => ({
|
|
|
|
type: RECEIVE_HISTORY_FOR_TOGGLE,
|
|
|
|
value: json,
|
|
|
|
});
|
|
|
|
|
2016-11-10 14:26:24 +01:00
|
|
|
const errorReceiveHistory = (statusCode) => ({
|
|
|
|
type: ERROR_RECEIVE_HISTORY,
|
|
|
|
statusCode,
|
|
|
|
});
|
|
|
|
|
|
|
|
export function fetchHistory () {
|
|
|
|
return dispatch => api.fetchAll()
|
|
|
|
.then(json => dispatch(receiveHistory(json)))
|
|
|
|
.catch(error => dispatch(errorReceiveHistory(error)));
|
|
|
|
}
|
2016-12-05 17:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
export function fetchHistoryForToggle (toggleName) {
|
|
|
|
return dispatch => api.fetchHistoryForToggle(toggleName)
|
|
|
|
.then(json => dispatch(receiveHistoryforToggle(json)))
|
|
|
|
.catch(error => dispatch(errorReceiveHistory(error)));
|
|
|
|
}
|