- Linting... Prettier...
This commit is contained in:
@@ -1,36 +1,31 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
import { fetchEvents as fetchEventsApi } from '../api/events.js';
|
||||
import {
|
||||
EVENTS_LOAD_FAILED,
|
||||
EVENTS_LOADED,
|
||||
GET_EVENTS,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { EVENTS_LOAD_FAILED, EVENTS_LOADED, GET_EVENTS } from '../constants/actionTypes.js';
|
||||
import Event from '../domain/Event.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
const beginFetchEvents = () => ({ type: GET_EVENTS });
|
||||
|
||||
const eventsLoaded = (payload) => ({ type: EVENTS_LOADED, payload });
|
||||
|
||||
const eventsLoadError = (payload) => ({ type: EVENTS_LOAD_FAILED, payload });
|
||||
|
||||
const eventsFetchSuccess = (items) => (dispatch) => {
|
||||
const payload = List(items).map((i) => Event.fromJS(i));
|
||||
|
||||
dispatch(eventsLoaded(payload));
|
||||
dispatch(unblockUI);
|
||||
const payload = List(items).map((i) => Event.fromJS(i));
|
||||
dispatch(eventsLoaded(payload));
|
||||
};
|
||||
|
||||
const eventsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::events::eventsFetchFailure]', error);
|
||||
dispatch(eventsLoadError(error));
|
||||
dispatch(unblockUI);
|
||||
console.error('[actions::events::eventsFetchFailure]', error);
|
||||
dispatch(eventsLoadError(error));
|
||||
};
|
||||
|
||||
export const fetchEvents = () => (dispatch, getState) => {
|
||||
const authToken = getAuthToken(getState());
|
||||
const authToken = getAuthToken(getState());
|
||||
|
||||
fetchEventsApi(authToken)
|
||||
.then(payload => dispatch(eventsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(eventsFetchFailure(err)));
|
||||
dispatch(beginFetchEvents());
|
||||
fetchEventsApi(authToken)
|
||||
.then((payload) => dispatch(eventsFetchSuccess(payload)))
|
||||
.catch((err) => dispatch(eventsFetchFailure(err)));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user