detailReducer.js
2.08 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
'use strict';
import InitialState from './detailInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_PRODUCT_SKN,
GET_DETAIL_REQUEST,
GET_DETAIL_SUCCESS,
GET_DETAIL_FAILURE,
GET_SIMILAR_REQUEST,
GET_SIMILAR_SUCCESS,
GET_SIMILAR_FAILURE,
SET_FAVORITE_STATUS,
SET_DETAIL_PRAISE,
SET_DETAIL_TOTAL_PRAISE,
DETAIL_LIKE_REQUEST,
DETAIL_LIKE_SUCCESS,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case DETAIL_LIKE_REQUEST: {
return state.set('liking', true);
}
case DETAIL_LIKE_SUCCESS: {
let {
likeStatus,
likeCount,
} = action.payload;
return state.set('liking', false)
.set('total_praised', likeCount)
.set('is_praised', likeStatus);
}
case SET_DETAIL_TOTAL_PRAISE: {
return state.set('total_praised', action.payload);
}
case SET_DETAIL_PRAISE: {
return state.set('is_praised', action.payload);
}
case SET_FAVORITE_STATUS: {
return state.set('favorite', action.payload);
}
case SET_PRODUCT_SKN: {
return state.set('product_skn', action.payload);
}
case GET_DETAIL_REQUEST: {
return state.setIn(['product', 'isFetching'], true);
}
case GET_DETAIL_SUCCESS: {
return state.setIn(['product', 'isFetching'], false)
.setIn(['product', 'data'], Immutable.fromJS(action.payload))
.setIn(['product', 'error'], null);
}
case GET_DETAIL_FAILURE: {
return state.setIn(['product', 'isFetching'], false)
.setIn(['product', 'error'], action.payload);
}
case GET_SIMILAR_REQUEST: {
return state.setIn(['similarList', 'isFetching'], true);
}
case GET_SIMILAR_SUCCESS: {
return state.setIn(['similarList', 'isFetching'], false)
.setIn(['similarList', 'data'], Immutable.fromJS(action.payload))
.setIn(['similarList', 'error'], null);
}
case GET_SIMILAR_FAILURE: {
return state.setIn(['similarList', 'isFetching'], false)
.setIn(['similarList', 'error'], action.payload);
}
}
return state;
}