contentReducer.js
6.57 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
'use strict';
import InitialState from './contentInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_CONTENT_LIST_ID,
SET_CONTENT_CATEGORY_NAME,
SET_CONTENT_TIP_FLAG,
FETCH_CONTENT_TYPE_REQUEST,
FETCH_CONTENT_TYPE_SUCCESS,
FETCH_CONTENT_TYPE_FAILURE,
FETCH_CONTENT_LIST_REQUEST,
FETCH_CONTENT_LIST_SUCCESS,
FETCH_CONTENT_LIST_FAILURE,
//main评论内容
FETCH_COMMENT_LIST_REQUEST,
FETCH_COMMENT_LIST_SUCCESS,
FETCH_COMMENT_LIST_FAILURE,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST,
ADD_ARTICLE_COMMENT_SUCCESS,
ADD_ARTICLE_COMMENT_FAILURE,
//关注用户
UPDATE_ATTENTION_REQUEST,
UPDATE_ATTENTION_SUCCESS,
UPDATE_ATTENTION_FAILURE,
//清除消息内容
MESSAGE_CLEAR_OTHER_LIST,
MESSAGE_CLEAR_COMMENT_LIST,
//回复成功提示
SHOW_REPLY_TIP_MESSAGE,
HIDDEN_REPLY_TIP_MESSAGE,
CLEAR_BADGE_NUM_SUCCESS,
UPDATE_TIP_FLAG_SUCCESS,
SHOW_TOAST,
HIDE_TOAST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function grassReducer(state=initialState, action) {
switch(action.type) {
case SET_CONTENT_LIST_ID: {
return state.set('contentListId', action.payload);
}
case SET_CONTENT_CATEGORY_NAME: {
return state.set('contentCategoryName', action.payload);
}
case SET_CONTENT_TIP_FLAG: {
return state.set('contentTipFlag', action.payload);
}
case FETCH_CONTENT_TYPE_REQUEST: {
return state.setIn(['contentType', 'isFetching'], true)
}
case FETCH_CONTENT_TYPE_SUCCESS: {
return state.setIn(['contentType', 'isFetching'], false)
.setIn(['contentType', 'list'], Immutable.fromJS(action.payload))
}
case FETCH_CONTENT_TYPE_FAILURE: {
return state.setIn(['contentType', 'isFetching'], false)
.setIn(['contentType', 'error'], action.payload)
}
case FETCH_COMMENT_LIST_REQUEST: {
return state.setIn(['commentList', 'isFetching'], true)
.setIn(['commentList', 'isPullToRefresh'], action.isRefresh == true)
}
case FETCH_COMMENT_LIST_SUCCESS: {
state = state
.setIn(['commentList', 'isFetching'], false)
.setIn(['commentList', 'list'], Immutable.fromJS((action.payload.list)))
.setIn(['commentList', 'currentPage'], action.payload.currentPage)
.setIn(['commentList', 'endReached'], action.payload.endReached)
.setIn(['commentList', 'isPullToRefresh'], false)
.setIn(['commentList', 'pageCount'], action.payload.pageCount)
.setIn(['commentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty)
return state;
}
case FETCH_COMMENT_LIST_FAILURE: {
return state.setIn(['commentList', 'isFetching'], false)
.setIn(['commentList', 'isPullToRefresh'], false)
.setIn(['commentList', 'error'], action.payload)
.setIn(['commentList', 'shouldShowEmpty'], true);
}
case FETCH_CONTENT_LIST_REQUEST: {
return state.setIn(['contentList', 'isFetching'], true)
.setIn(['contentList', 'isPullToRefresh'], action.isRefresh == true)
}
case FETCH_CONTENT_LIST_SUCCESS: {
state = state
.setIn(['contentList', 'isFetching'], false)
.setIn(['contentList', 'list'], Immutable.fromJS((action.payload.list)))
.setIn(['contentList', 'currentPage'], action.payload.currentPage)
.setIn(['contentList', 'endReached'], action.payload.endReached)
.setIn(['contentList', 'isPullToRefresh'], false)
.setIn(['contentList', 'pageCount'], action.payload.pageCount)
.setIn(['contentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty)
return state;
}
case FETCH_CONTENT_LIST_FAILURE: {
return state.setIn(['contentList', 'isFetching'], false)
.setIn(['contentList', 'isPullToRefresh'], false)
.setIn(['contentList', 'error'], action.payload)
.setIn(['contentList', 'shouldShowEmpty'], true);
}
case ADD_ARTICLE_COMMENT_REQUEST: {
return state.setIn(['addCommentContent', 'isFetching'], true);
}
case ADD_ARTICLE_COMMENT_SUCCESS: {
return state.setIn(['addCommentContent', 'isFetching'], false);
}
case ADD_ARTICLE_COMMENT_FAILURE: {
return state.setIn(['addCommentContent', 'isFetching'], false)
.setIn(['addCommentContent', 'error'], action.payload);
}
case UPDATE_ATTENTION_REQUEST: {
return state.setIn(['updateAttentionContent', 'isFetching'], true);
}
case UPDATE_ATTENTION_SUCCESS: {
state = state.setIn(['updateAttentionContent', 'isFetching'], false);
let list = state.contentList.get('list').toJS();
return state.setIn(['contentList', 'list'], Immutable.fromJS(list.map((item)=> {
if (item.uid == action.optUid) {
return Object.assign({}, item, {
isMutualAttention: !item.isMutualAttention
})
}
return item;
})))
}
case UPDATE_ATTENTION_FAILURE: {
return state.setIn(['updateAttentionContent', 'isFetching'], false)
.setIn(['updateAttentionContent', 'error'], action.payload);
}
case MESSAGE_CLEAR_OTHER_LIST: {
return state.set('contentList', initialState.get('contentList'))
}
case MESSAGE_CLEAR_COMMENT_LIST: {
return state.set('commentList', initialState.get('commentList'))
}
case SHOW_REPLY_TIP_MESSAGE: {
return state.set('tipMessage', Immutable.fromJS(action.payload));
}
case HIDDEN_REPLY_TIP_MESSAGE: {
return state.set('tipMessage', '');
}
case CLEAR_BADGE_NUM_SUCCESS: {
let typeList = state.contentType.get('list').toJS();
return state.setIn(['contentType', 'list'], Immutable.fromJS(typeList.map((item)=> {
if (item.type == action.payload) {
return Object.assign({}, item, {
unReadCount: 0
})
}
return item;
})));
}
case UPDATE_TIP_FLAG_SUCCESS: {
return state.set('contentTipFlag', action.payload);
}
case SHOW_TOAST:
return state.set('isShowToast', true).set('toastMessage', action.payload)
case HIDE_TOAST:
return state.set('isShowToast', false).set('toastMessage', '')
}
return state;
}