|
@@ -1,12 +1,9 @@
|
|
|
-import { Action, TopicsState, Topic, TopicCustomParam } from 'redux/interfaces';
|
|
|
+import { Action, TopicsState, Topic } from 'redux/interfaces';
|
|
|
import { ActionType } from 'redux/actionType';
|
|
|
|
|
|
export const initialState: TopicsState = {
|
|
|
byName: {},
|
|
|
allNames: [],
|
|
|
- customParams: {
|
|
|
- byName: {},
|
|
|
- },
|
|
|
};
|
|
|
|
|
|
const updateTopicList = (state: TopicsState, payload: Topic[]): TopicsState => {
|
|
@@ -30,25 +27,6 @@ const updateTopicList = (state: TopicsState, payload: Topic[]): TopicsState => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-const setTopicsCustomParams = (state: TopicsState, payload: TopicCustomParam[]): TopicsState => {
|
|
|
- const initialMemo: TopicsState = {
|
|
|
- ...state,
|
|
|
- customParams: {
|
|
|
- ...state.customParams,
|
|
|
- byName: {},
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- return payload.reduce(
|
|
|
- (memo: TopicsState, topicCustomParam) => {
|
|
|
- memo.customParams.byName[topicCustomParam.name] = topicCustomParam;
|
|
|
-
|
|
|
- return memo;
|
|
|
- },
|
|
|
- initialMemo,
|
|
|
- );
|
|
|
-};
|
|
|
-
|
|
|
const addToTopicList = (state: TopicsState, payload: Topic): TopicsState => {
|
|
|
const newState: TopicsState = {
|
|
|
...state
|
|
@@ -86,8 +64,6 @@ const reducer = (state = initialState, action: Action): TopicsState => {
|
|
|
};
|
|
|
case ActionType.POST_TOPIC__SUCCESS:
|
|
|
return addToTopicList(state, action.payload);
|
|
|
- case ActionType.GET_TOPICS_CUSTOM_PARAMS__SUCCESS:
|
|
|
- return setTopicsCustomParams(state, action.payload);
|
|
|
default:
|
|
|
return state;
|
|
|
}
|