import * as types from "../actionTypes/actionTypes";

export const getEvents = payload => ({
    type: types.GET_REQUEST_EVENTS,
    payload
});

export const getEventsSuccess = payload => ({
    type: types.GET_REQUEST_SUCCESS_EVENTS,
    payload
});

export const getEventsError = payload => ({
    type: types.GET_REQUEST_ERROR_EVENTS,
    payload
});

export const getAllEvents = () => {
    return dispatch => {
        let promise = fetch("https://api-marathon.herokuapp.com/api/v1/event")

        dispatch(getEvents())

        promise.then(
            data => data.json().then(data => dispatch(getEventsSuccess(data))),
            error => dispatch(getEventsError(error))
        )
    }
}