...
|
...
|
@@ -45,16 +45,35 @@ export default function sectionReducer(state = initialState, action) { |
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
case GO_TO_SECTION: {
|
|
|
let sid = state.sid + 1;
|
|
|
// 获取新的初始状态item
|
|
|
let item = initialState.item;
|
|
|
// 设置item的value
|
|
|
item = item.set('id', action.payload.id)
|
|
|
.set('name', action.payload.name);
|
|
|
// items新增item
|
|
|
let newItems = state.items.push(item);
|
|
|
let nextState = state.set('sid', sid)
|
|
|
.set('items', newItems);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HEADER_REQUEST: {
|
|
|
let nextState = state.set('isFetching', true)
|
|
|
.set('error', null);
|
|
|
let sid = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'isFetching'], true)
|
|
|
.setIn(['items', sid, 'error'], null)
|
|
|
.setIn(['items', sid, 'ptr'], true);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HEADER_SUCCESS: {
|
|
|
let {notice, header} = action.payload;
|
|
|
let nextState = state.set('isFetching', false)
|
|
|
let {sid, json} = action.payload;
|
|
|
let {notice, header} = json;
|
|
|
let item = state.items.get(sid);
|
|
|
item = item.set('isFetching', false)
|
|
|
.set('error', null)
|
|
|
.set('ptr', false)
|
|
|
.setIn(['header', 'uri'], header.uri)
|
|
|
.setIn(['header', 'title'], header.title)
|
|
|
.setIn(['header', 'post'], header.post)
|
...
|
...
|
@@ -63,67 +82,79 @@ export default function sectionReducer(state = initialState, action) { |
|
|
.setIn(['notice', 'duration'], notice.duration)
|
|
|
.setIn(['notice', 'open'], notice.open)
|
|
|
.setIn(['notice', 'list'], Immutable.fromJS(notice.list));
|
|
|
let nextState = state.setIn(['items', sid], item);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HEADER_FAILURE: {
|
|
|
let nextState = state.set('isFetching', false)
|
|
|
.set('error', action.payload);
|
|
|
let {sid, error} = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'isFetching'], false)
|
|
|
.setIn(['items', sid, 'error'], error)
|
|
|
.setIn(['items', sid, 'ptr'], false);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HOT_POST_REQUEST: {
|
|
|
let nextState = state.setIn(['hot', 'isFetching'], true)
|
|
|
.setIn(['hot', 'error'], null)
|
|
|
.set('ptr', action.payload);
|
|
|
let {sid, ptr} = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'hot', 'isFetching'], true)
|
|
|
.setIn(['items', sid, 'hot', 'error'], null);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HOT_POST_SUCCESS: {
|
|
|
let {lastedTime, list, endReached} = action.payload;
|
|
|
let nextState = state.setIn(['hot', 'isFetching'], false)
|
|
|
let {sid, json} = action.payload;
|
|
|
let {lastedTime, list, endReached} = json;
|
|
|
let item = state.items.get(sid);
|
|
|
item = item.setIn(['hot', 'isFetching'], false)
|
|
|
.setIn(['hot', 'error'], null)
|
|
|
.setIn(['hot', 'lastedTime'], lastedTime)
|
|
|
.setIn(['hot', 'endReached'], endReached)
|
|
|
.setIn(['hot', 'list'], Immutable.fromJS(list));
|
|
|
let nextState = state.setIn(['items', sid], item);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_HOT_POST_FAILURE: {
|
|
|
let nextState = state.setIn(['hot', 'isFetching'], false)
|
|
|
.setIn(['hot', 'error'], action.payload);
|
|
|
let {sid, error} = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'hot', 'isFetching'], false)
|
|
|
.setIn(['items', sid, 'hot', 'error'], error);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_NEW_POST_REQUEST: {
|
|
|
let nextState = state.setIn(['new', 'isFetching'], true)
|
|
|
.setIn(['new', 'error'], null)
|
|
|
.set('ptr', action.payload);
|
|
|
let {sid, ptr} = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'new', 'isFetching'], true)
|
|
|
.setIn(['items', sid, 'new', 'error'], null);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_NEW_POST_SUCCESS: {
|
|
|
let {lastedTime, list, endReached} = action.payload;
|
|
|
let nextState = state.setIn(['new', 'isFetching'], false)
|
|
|
let {sid, json} = action.payload;
|
|
|
let {lastedTime, list, endReached} = json;
|
|
|
let item = state.items.get(sid);
|
|
|
item = item.setIn(['new', 'isFetching'], false)
|
|
|
.setIn(['new', 'error'], null)
|
|
|
.setIn(['new', 'lastedTime'], lastedTime)
|
|
|
.setIn(['new', 'endReached'], endReached)
|
|
|
.setIn(['new', 'list'], Immutable.fromJS(list));
|
|
|
let nextState = state.setIn(['items', sid], item);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_NEW_POST_FAILURE: {
|
|
|
let nextState = state.setIn(['new', 'isFetching'], false)
|
|
|
.setIn(['new', 'error'], action.payload);
|
|
|
let {sid, error} = action.payload;
|
|
|
let nextState = state.setIn(['items', sid, 'new', 'isFetching'], false)
|
|
|
.setIn(['items', sid, 'new', 'error'], error);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case SECTION_SET_ACTIVE_TAB:
|
|
|
return state.set('activeTab', action.payload);
|
|
|
|
|
|
case GO_TO_SECTION:
|
|
|
return state.set('id', action.payload.id)
|
|
|
.set('name', action.payload.name);
|
|
|
case SECTION_SET_ACTIVE_TAB: {
|
|
|
let {sid, tab} = action.payload;
|
|
|
let item = state.items.get(sid);
|
|
|
item = item.set('activeTab', tab);
|
|
|
let nextState = state.setIn(['items', sid], item);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case POST_LIKE_REQUEST: {
|
|
|
return newLikeState(state, action.payload, true);
|
...
|
...
|
@@ -133,8 +164,15 @@ export default function sectionReducer(state = initialState, action) { |
|
|
return newLikeState(state, action.payload, false);
|
|
|
}
|
|
|
|
|
|
case SECTION_CLEAN:
|
|
|
return initialState;
|
|
|
case SECTION_CLEAN: {
|
|
|
let sid = action.payload;
|
|
|
if (state.items.size > sid) {
|
|
|
let items = state.items.pop();
|
|
|
let nextState = state.set('sid', sid - 1)
|
|
|
.set('items', items);
|
|
|
return nextState;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return state;
|
...
|
...
|
@@ -163,10 +201,15 @@ function newLikeState(state, postId, like) { |
|
|
return nextList;
|
|
|
};
|
|
|
|
|
|
let hotList = likeState(state.hot.list, postId, like);
|
|
|
let newList = likeState(state.new.list, postId, like);
|
|
|
let nextState = state;
|
|
|
state.items.map((item, i) => {
|
|
|
let hotList = likeState(item.hot.list, postId, like);
|
|
|
let newList = likeState(item.new.list, postId, like);
|
|
|
|
|
|
let nextState = state.setIn(['hot', 'list'], hotList)
|
|
|
item = item.setIn(['hot', 'list'], hotList)
|
|
|
.setIn(['new', 'list'], newList);
|
|
|
nextState = nextState.setIn(['items', i], item);
|
|
|
});
|
|
|
|
|
|
return nextState;
|
|
|
} |
...
|
...
|
|