productListPoolReducer.js
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
import InitialState from './productListPoolInitialState';
import Immutable, {Map} from 'immutable';
const {
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
PRODUCT_FILTER_ACTION,
SET_SIMILAR_PRODUCT_INDEX,
SET_PRODUCT_LIST_FILTER,
RESET_LIST_PAGE_INFO,
GET_BANNERLIST_REQUEST,
GET_BANNERLIST_SUCCESS,
GET_BANNERLIST_FAILURE,
GET_ACTIVITY_REQUEST,
GET_ACTIVITY_SUCCESS,
GET_ACTIVITY_FAILURE,
SELECT_LATEST_TAB_INDEX,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function productListPoolReducer(state=initialState, action) {
switch(action.type) {
case RESET_LIST_PAGE_INFO: {
return state.setIn(['productList', 'currentPage'], 0)
.setIn(['productList', 'pageCount'], 0)
.setIn(['productList', 'total'], 0)
.setIn(['productList', 'endReached'], false);
}
case SET_PRODUCT_LIST_FILTER: {
return state.setIn(['productList', 'order'], action.payload);
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
list,
categoryFilterList,
filterCategoryDetailFilterList,
currentPage,
pageCount,
total,
recId,
endReached,
latestTabs,
} = action.payload;
let newState = state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'list'], Immutable.fromJS(list))
.setIn(['productList', 'currentPage'], currentPage)
.setIn(['productList', 'pageCount'], pageCount)
.setIn(['productList', 'total'], total)
.setIn(['productList', 'endReached'], endReached);
if (currentPage == 1 && state.categoryFilterList.size == 0 && state.filterCategoryDetailFilterList.size == 0) {
newState = newState.set('categoryFilterList', Immutable.fromJS(categoryFilterList))
.set('filterCategoryDetailFilterList', Immutable.fromJS(filterCategoryDetailFilterList));
}
if (currentPage == 1 && state.latestTabs.size == 0) {
newState = newState.set('latestTabs', Immutable.fromJS(latestTabs));
}
return newState;
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
case PRODUCT_FILTER_ACTION: {
return state.set('filterFactors', Immutable.fromJS(action.payload));
}
case SET_SIMILAR_PRODUCT_INDEX: {
return state.set('similarIndex', action.payload);
}
case GET_BANNERLIST_REQUEST: {
return state.setIn(['bannerInfo', 'isFetching'], true)
.setIn(['bannerInfo', 'error'], '');
}
case GET_BANNERLIST_SUCCESS: {
return state.setIn(['bannerInfo', 'isFetching'], false)
.setIn(['bannerInfo', 'list'], Immutable.fromJS(action.payload));
}
case GET_BANNERLIST_FAILURE: {
return state.setIn(['bannerInfo', 'isFetching'], false)
.setIn(['bannerInfo', 'error'], action.payload);
}
case GET_ACTIVITY_REQUEST: {
return state.setIn(['activityInfo', 'isFetching'], true)
.setIn(['activityInfo', 'error'], '');
}
case GET_ACTIVITY_SUCCESS: {
return state.setIn(['activityInfo', 'isFetching'], false)
.setIn(['activityInfo', 'list'], Immutable.fromJS(action.payload))
.setIn(['activityInfo', 'productPool'], action.payload[0].productPoolId);
}
case GET_ACTIVITY_FAILURE: {
return state.setIn(['activityInfo', 'isFetching'], false)
.setIn(['activityInfo', 'error'], action.payload);
}
case SELECT_LATEST_TAB_INDEX: {
return state.set('selectLatestItem', action.payload);
}
}
return state;
}