getSubCategory condition check

This commit is contained in:
hyunwoo93.cha
2024-06-28 15:22:34 +09:00
parent 6515e96f8c
commit 9dd108184a

View File

@@ -23,19 +23,56 @@ export const mainReducer = (state = initialState, action) => {
case types.GET_SUB_CATEGORY: {
const dataType = action.payload.categoryShowInfos
? "categoryShowInfos"
: "categoryItemInfos";
const subKey = action.payload[dataType].subCatShowList
: action.payload.categoryItemInfos
? "categoryItemInfos"
: null;
if (!dataType) {
return {
...state,
subCategoryData: {
...state.subCategoryData,
categoryShowInfos: { subCatShowList: [], total: 0 },
categoryItemInfos: { subCatItemList: [], total: 0 },
},
categoryFilterCd: action.payload.categoryFilterCd,
topShowInfo: action.payload.topShowInfo,
categoryParams: action.categoryParams,
};
}
const subKey = action.payload[dataType]?.subCatShowList
? "subCatShowList"
: "subCatItemList";
const newResults = action.payload[dataType][subKey];
const total = action.payload[dataType].total;
: action.payload[dataType]?.subCatItemList
? "subCatItemList"
: null;
if (!subKey) {
return {
...state,
subCategoryData: {
...state.subCategoryData,
[dataType]: {
subCatShowList: [],
subCatItemList: [],
total: 0,
},
},
categoryFilterCd: action.payload.categoryFilterCd,
topShowInfo: action.payload.topShowInfo,
categoryParams: action.categoryParams,
};
}
const newResults = action.payload[dataType][subKey] || [];
const total = action.payload[dataType].total || 0;
if (action.append) {
const existingData = state.subCategoryData[dataType] || {
[subKey]: [],
total: 0,
};
const existingSubData = existingData[subKey];
const existingSubData = existingData[subKey] || [];
for (let i = 0; i < newResults.length; i++) {
existingSubData[action.startIndex + i] = newResults[i];