Skip to content

Instantly share code, notes, and snippets.

@maiordom
Created October 13, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maiordom/1c6dcc1ae871c7ef6d41ed18aaa53e22 to your computer and use it in GitHub Desktop.
Save maiordom/1c6dcc1ae871c7ef6d41ed18aaa53e22 to your computer and use it in GitHub Desktop.
import { handleActions } from 'redux-actions';
import * as find from 'lodash/find';
import * as each from 'lodash/each';
import * as a from 'src/actions/Shop';
import { IWebShopServices, IWebShopService } from 'src/types/IWebShopServices';
import { IProductCard, IShopService, IShopServices } from 'src/store/ShopService';
import { IShopCategory } from 'src/store/ShopCategories';
export default handleActions({
[a.setProducts]: (state, { payload: { products, serviceName } }) => {
const items: Array<IProductCard> = products.items;
state.setIn(`shopService.${serviceName}`, { items });
const itemsPerPage: number = state.getIn('shop.controls.perPageCount.selected.value');
const pageCount: number = Math.round(products.total / itemsPerPage);
state.setIn(`shopService.${serviceName}.pagination`, { pageCount });
return state;
},
[a.setShopServices]: (state, { payload }) => {
const services: IWebShopServices = payload.services;
const shopService: IShopServices = state.getIn('shopService');
services.forEach((service: IWebShopService) => {
each(shopService, (game: IShopService) => {
if (game.name === service.name) {
game.serviceId = service.id;
}
});
});
return state;
},
[a.setShopCategory]: (state, { payload }) => {
const category: IShopCategory = payload.category;
const serviceName: string = payload.serviceName;
state.setIn(`shopCategories.${serviceName}`, category);
return state;
}
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment