contentReducer.js
5.41 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
'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,
//回复评论
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,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
function getContentListObject(isLatest) {
return isLatest ? 'commentList' : 'contentList';
}
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_CONTENT_LIST_REQUEST: {
return state.setIn([getContentListObject(action.isLatest), 'isFetching'], true)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], action.isRefresh == true)
}
case FETCH_CONTENT_LIST_SUCCESS: {
state = state
.setIn([getContentListObject(action.isLatest), 'isFetching'], false)
.setIn([getContentListObject(action.isLatest), 'list'], Immutable.fromJS((action.payload.list)))
.setIn([getContentListObject(action.isLatest), 'currentPage'], action.payload.currentPage)
.setIn([getContentListObject(action.isLatest), 'endReached'], action.payload.endReached)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false)
.setIn([getContentListObject(action.isLatest), 'pageCount'], action.payload.pageCount)
.setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], action.payload.shouldShowEmpty)
return state;
}
case FETCH_CONTENT_LIST_FAILURE: {
return state.setIn([getContentListObject(action.isLatest), 'isFetching'], false)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false)
.setIn([getContentListObject(action.isLatest), 'error'], action.payload)
.setIn([getContentListObject(action.isLatest), '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;
})));
}
}
return state;
}