haggleReducer.js
6.33 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
import InitialState from './haggleInitialState';
import Immutable, {List} from 'immutable';
const {
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
MYHAGGLE_PRODUCT_LIST_REQUEST,
MYHAGGLE_PRODUCT_LIST_SUCCESS,
MYHAGGLE_PRODUCT_LIST_FAILURE,
RESOURCE_INFO_REQUEST,
RESOURCE_INFO_SUCCESS,
RESOURCE_INFO_FAILURE,
SET_SELECTED_CATEGORY,
SHOW_HASCUT_ALERT,
REFRESH_PRODUCT_LIST,
PRODUCT_UFO_LIST_SUCCESS,
PRODUCT_UFO_LIST_REQUEST,
PRODUCT_UFO_LIST_FAILURE
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function couponReducer(state = initialState, action) {
if (!(state instanceof InitialState)) {
return initialState.merge(state);
}
switch (action.type) {
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
page,
page_total,
endReached,
list,
} = action.payload;
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'page'], page)
.setIn(['productList', 'page_total'], page_total)
.setIn(['productList', 'endReached'], endReached)
.setIn(['productList', 'list'], Immutable.fromJS(list))
.setIn(['productList', 'error'], null)
.setIn(['productList', 'isPullToRefresh'], false);
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload)
.setIn(['productList', 'isPullToRefresh'], false);
}
case PRODUCT_UFO_LIST_REQUEST: {
return state.setIn(['productUFOList', 'isFetching'], true)
.setIn(['productUFOList', 'error'], null);
}
case PRODUCT_UFO_LIST_SUCCESS: {
let {
page,
page_total,
endReached,
list,
} = action.payload;
return state.setIn(['productUFOList', 'isFetching'], false)
.setIn(['productUFOList', 'page'], page)
.setIn(['productUFOList', 'page_total'], page_total)
.setIn(['productUFOList', 'endReached'], endReached)
.setIn(['productUFOList', 'list'], Immutable.fromJS(list))
.setIn(['productUFOList', 'error'], null)
.setIn(['productUFOList', 'isPullToRefresh'], false);
}
case PRODUCT_UFO_LIST_FAILURE: {
return state.setIn(['productUFOList', 'isFetching'], false)
.setIn(['productUFOList', 'error'], action.payload)
.setIn(['productUFOList', 'isPullToRefresh'], false);
}
case MYHAGGLE_PRODUCT_LIST_REQUEST: {
return state.setIn(['myHaggleProductList', 'isFetching'], true)
.setIn(['myHaggleProductList', 'error'], null);
}
case MYHAGGLE_PRODUCT_LIST_SUCCESS: {
let {
page,
page_total,
endReached,
list,
} = action.payload;
return state.setIn(['myHaggleProductList', 'isFetching'], false)
.setIn(['myHaggleProductList', 'page'], page)
.setIn(['myHaggleProductList', 'page_total'], page_total)
.setIn(['myHaggleProductList', 'endReached'], endReached)
.setIn(['myHaggleProductList', 'list'], Immutable.fromJS(list))
.setIn(['myHaggleProductList', 'error'], null)
.setIn(['myHaggleProductList', 'isPullToRefresh'], false);
}
case MYHAGGLE_PRODUCT_LIST_FAILURE: {
return state.setIn(['myHaggleProductList', 'isFetching'], false)
.setIn(['myHaggleProductList', 'error'], action.payload)
.setIn(['myHaggleProductList', 'isPullToRefresh'], false);
}
case SET_SELECTED_CATEGORY: {
return state.set('categoryType', action.payload);
}
case REFRESH_PRODUCT_LIST: {
let {
index,
} = action.payload;
if (index === 0) {
return state.setIn(['productList', 'page'], 0)
.setIn(['productList', 'page_total'], 0)
.setIn(['productList', 'endReached'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'isPullToRefresh'], true)
.setIn(['productUFOList', 'page'], 0)
.setIn(['productUFOList', 'page_total'], 0)
.setIn(['productUFOList', 'endReached'], false)
.setIn(['productUFOList', 'error'], null)
.setIn(['productUFOList', 'isFetching'], false)
.setIn(['productUFOList', 'isPullToRefresh'], true);
} else {
return state.setIn(['myHaggleProductList', 'page'], 0)
.setIn(['myHaggleProductList', 'page_total'], 0)
.setIn(['myHaggleProductList', 'endReached'], false)
.setIn(['myHaggleProductList', 'error'], null)
.setIn(['myHaggleProductList', 'isFetching'], false)
.setIn(['myHaggleProductList', 'isPullToRefresh'], true);
}
}
break;
case SHOW_HASCUT_ALERT: {
return state.set('isShowAlert', true);
}
case RESOURCE_INFO_REQUEST: {
return state.setIn(['resourceInfo', 'isFetching'], true)
.setIn(['resourceInfo', 'error'], action.payload);
}
case RESOURCE_INFO_SUCCESS: {
return state.setIn(['resourceInfo', 'isFetching'], false)
.setIn(['resourceInfo', 'resourceList'], Immutable.fromJS(action.payload))
.setIn(['resourceInfo', 'error'], null);
}
case RESOURCE_INFO_FAILURE: {
return state.setIn(['resourceInfo', 'isFetching'], false)
.setIn(['resourceInfo', 'error'], null);
}
}
return state;
}