export const fetchCollections = (_options = {}) => (dispatch, getState) => { const { collections: { perPage, page, sort, filters }, auth: { token }, } = getState() const options = { perPage, page, sort, filters, ..._options, } dispatch({ type: FETCH_COLLECTIONS_REQUEST, ...options }) return api.collections.find(options, { apiUrl, token }) .then(res => { dispatch(fetchTime({ type: FETCH_COLLECTIONS_SUCCESS, ...res, })) }) .catch(error => { dispatch({ type: FETCH_COLLECTIONS_FAILURE, error, }) }) }
export const fetchCollectionComments = (id, _options = {}) => (dispatch, getState) => { const { collections: { perPage, page, sort, filters }, auth: { token }, } = getState() const options = { perPage, page, sort, filters, ..._options, } dispatch({ type: FETCH_COLLECTION_COMMENTS_REQUEST, id, ...options }) return api.collections.comments(id, options, { token, apiUrl }) .then(res => { dispatch(fetchTime({ type: FETCH_COLLECTION_COMMENTS_SUCCESS, id, ...res, })) }) .catch(error => { dispatch({ type: FETCH_COLLECTION_COMMENTS_FAILURE, id, error, }) }) }