searchPanel 검색 후 ui 업데이트 로직 변경 / reducer, action 함수 수정

This commit is contained in:
hyunwoo93.cha
2024-02-03 02:06:14 +09:00
parent 75458ac163
commit c75c65de54
7 changed files with 98 additions and 57 deletions

View File

@@ -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 {