27 lines
850 B
JavaScript
27 lines
850 B
JavaScript
|
import { GET_CATALOG } from '../actions/catalog';
|
||
|
import { FETCH_ADS_SUCCESS, FETCH_ADS_ERROR, updateAds } from '../actions/ads';
|
||
|
import { apiRequest } from '../actions/api';
|
||
|
import { showSpinner, hideSpinner } from '../actions/ui';
|
||
|
|
||
|
export const getAdsFlow = store => next => action => {
|
||
|
next(action);
|
||
|
|
||
|
const state = store.getState();
|
||
|
if (action.type === GET_CATALOG && !state.ui.isPreLaunch) {
|
||
|
store.dispatch(apiRequest('GET', state.urls.ads, null, FETCH_ADS_SUCCESS, FETCH_ADS_ERROR));
|
||
|
store.dispatch(showSpinner());
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// on successful fetch, process the ads data
|
||
|
export const processAdsCollection = ({ dispatch }) => next => action => {
|
||
|
next(action);
|
||
|
|
||
|
if (action.type === FETCH_ADS_SUCCESS) {
|
||
|
dispatch(updateAds(action.payload.results));
|
||
|
dispatch(hideSpinner());
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export const adsMdl = [getAdsFlow, processAdsCollection];
|