searchPanel 검색 후 ui 업데이트 로직 변경 / reducer, action 함수 수정
This commit is contained in:
@@ -2,28 +2,35 @@ import { types } from "../actions/actionTypes";
|
||||
|
||||
const initialState = {
|
||||
searchDatas: {},
|
||||
processedDatas: {
|
||||
data: {},
|
||||
totalCount: {},
|
||||
},
|
||||
totalCount: {},
|
||||
searchPerformed: false,
|
||||
};
|
||||
|
||||
export const searchReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case types.GET_SEARCH:
|
||||
return {
|
||||
...state,
|
||||
searchDatas: action.payload,
|
||||
searchPerformed: true,
|
||||
};
|
||||
case types.GET_SEARCH: {
|
||||
const newResults = action.payload.data.result.results;
|
||||
|
||||
const updatedSearchDatas = action.append ? { ...state.searchDatas } : {};
|
||||
newResults.forEach(({ type, docs }) => {
|
||||
updatedSearchDatas[type] =
|
||||
action.append && updatedSearchDatas[type]
|
||||
? updatedSearchDatas[type].concat(docs)
|
||||
: docs;
|
||||
});
|
||||
|
||||
const updatedTotalCount = action.append ? { ...state.totalCount } : {};
|
||||
newResults.forEach(({ type, total_count }) => {
|
||||
updatedTotalCount[type] = total_count;
|
||||
});
|
||||
|
||||
case types.GET_SEARCH_PROCESSED:
|
||||
return {
|
||||
...state,
|
||||
processedDatas: action.payload,
|
||||
searchDatas: updatedSearchDatas,
|
||||
totalCount: updatedTotalCount,
|
||||
searchPerformed: true,
|
||||
};
|
||||
}
|
||||
|
||||
case types.RESET_SEARCH:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user