detailReducer.js
3.26 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
'use strict';
import InitialState from './detailInitialState';
import Immutable, {Map} from 'immutable';
const {
BRAND_INFO_REQUEST,
BRAND_INFO_SUCCESS,
BRAND_INFO_FAILURE,
JUMP_WITH_URL,
SET_ID,
SET_BRAND_ID,
SET_GENDER,
SET_BRAND_INTRO_UNFOLD,
SET_MORE_PRODUCT_URL,
CLEAR_ADD_CANCEL_TIP,
BRADN_FAV_REQUEST,
BRADN_FAV_SUCCESS,
BRADN_FAV_FAILURE,
NEW_ARRIVE_REQUEST,
NEW_ARRIVE_SUCCESS,
NEW_ARRIVE_FAILURE,
ARTICLE_BY_BRAND_REQUEST,
ARTICLE_BY_BRAND_SUCCESS,
ARTICLE_BY_BRAND_FAILURE,
ADD_FAVORITE_REQUEST,
ADD_FAVORITE_SUCCESS,
ADD_FAVORITE_FAILURE,
CANCEL_FAVORITE_REQUEST,
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
PRAISE_ARTICLE_CHANGE,
PRAISE_ARTICLE_REQUEST,
PRAISE_ARTICLE_SUCCESS,
PRAISE_ARTICLE_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function plustarReducer(state=initialState, action) {
switch(action.type) {
case BRAND_INFO_REQUEST: {
return state.setIn(['brandInfo', 'isFetching'], true)
.setIn(['brandInfo', 'error'], null);
}
case BRAND_INFO_SUCCESS: {
return state.setIn(['brandInfo', 'detail'], Immutable.fromJS(action.payload))
.setIn(['brandInfo', 'isFetching'], false)
.setIn(['brandInfo', 'error'], null);
}
case BRAND_INFO_FAILURE: {
return state.setIn(['brandInfo', 'isFetching'], false)
.setIn(['brandInfo', 'error'], action.payload);
}
case SET_ID:{
return state.set('id', action.payload);
}
case SET_BRAND_ID:{
return state.set('brandId', action.payload);
}
case SET_BRAND_INTRO_UNFOLD:{
return state.setIn(['brandInfo', 'titleUnfold'], action.payload);
}
case SET_MORE_PRODUCT_URL:{
return state.set('moreProductUrl', action.payload);
}
case CLEAR_ADD_CANCEL_TIP:{
return state.setIn(['brandInfo', 'addCancelTip'], '');
}
case NEW_ARRIVE_SUCCESS:{
return state.set('productList', Immutable.fromJS(action.payload));
}
case ARTICLE_BY_BRAND_SUCCESS:{
return state.set('articleList', Immutable.fromJS(action.payload));
}
case PRAISE_ARTICLE_CHANGE:{
let {index, isLiked, likenum} = action.payload;
let like = {isLiked: isLiked, count: likenum};
return state.setIn(['articleList', index, 'like'], Immutable.fromJS(like));
}
case PRAISE_ARTICLE_SUCCESS:
case PRAISE_ARTICLE_FAILURE:{
return state;
}
case BRADN_FAV_REQUEST:{
return state.setIn(['brandFav', 'isFetching'], true)
.setIn(['brandFav', 'error'], null);
}
case BRADN_FAV_SUCCESS:{
return state.setIn(['brandFav', 'isFetching'], false)
.setIn(['brandFav', 'isFav'], action.payload)
.setIn(['brandFav', 'error'], null);
}
case BRADN_FAV_FAILURE:{
return state.setIn(['brandFav', 'isFetching'], false)
.setIn(['brandFav', 'error'], action.payload);
}
case CANCEL_FAVORITE_SUCCESS:{
return state.setIn(['brandFav', 'isFav'], false)
.setIn(['brandFav', 'error'], null)
.setIn(['brandInfo', 'addCancelTip'], '取消收藏成功');
}
case ADD_FAVORITE_SUCCESS:{
return state.setIn(['brandFav', 'isFav'], true)
.setIn(['brandFav', 'error'], null)
.setIn(['brandInfo', 'addCancelTip'], '添加收藏成功');
}
break;
}
return state;
}