Parcourir la source

rtk_guery_goodsList1

Gennadysht il y a 2 ans
Parent
commit
ac84e95dfb

+ 3 - 3
src/Components/Pagination.js

@@ -1,8 +1,8 @@
 import { TablePagination } from '@mui/material';
 import { useState } from 'react';
 import { connect, useDispatch, useSelector } from 'react-redux';
-import { actionFindOrders, useGetGoodsQuery } from '../reducers';
-import { actionSetGoodsPaging, actionSetOrdersPaging, getCurrentCategory } from '../reducers/frontEndReducer';
+import { actionFindOrders } from '../reducers';
+import { actionSetGoodsPaging, actionSetOrdersPaging, getGoodsCount } from '../reducers';
 
 const Pagination = ({ allEntitiesCount, changePage, changePageFE, changeRowsPerPage, changeRowsPerPageFE }) => {
     allEntitiesCount = allEntitiesCount ?? 0;
@@ -51,7 +51,7 @@ export const COrdersPagination = connect(
 
 export const CGoodsPagination = () => {
     let state = useSelector(state => state);
-    let allEntitiesCount = state.frontend.goods.goodsCount?.payload ?? 0;
+    let allEntitiesCount = getGoodsCount(state);
     let dispatch = useDispatch();
     let changePageFE = (fromPage, pageSize) => dispatch(actionSetGoodsPaging({ fromPage, pageSize }));
     let changeRowsPerPageFE = pageSize => dispatch(actionSetGoodsPaging({ fromPage: 0, pageSize }));

+ 0 - 21
src/reducers/BAK/goodsReducer.js

@@ -1,21 +0,0 @@
-import { gqlGoodFind, gqlGoodFindOne, gqlGoodsCount } from '../gql/gqlGoods';
-import { createPromiseReducerSlice, actionPromiseGeneric } from './promiseReducer';
-
-const currentGood = 'currentGood';
-const actionGoodFindOne = (id) =>
-    actionPromiseGoods(currentGood, gqlGoodFindOne(id));
-const getCurrentGood = state => (
-    
-    state.goods[currentGood]?.payload
-)
-
-const actionGoodFind = (fromPage = 0, pageSize = undefined, searchStr = null, queryExt = {}) =>
-    actionPromiseGoods('goods', gqlGoodFind(fromPage, pageSize, searchStr, queryExt));
-const actionGoodsCount = (searchStr = null, queryExt = {}) =>
-    actionPromiseGoods('goodsCount', gqlGoodsCount(searchStr, queryExt));
-
-const goodsReducerSlice = createPromiseReducerSlice('goods');
-const actionPromiseGoods = (name, promise) =>
-    actionPromiseGeneric(goodsReducerSlice, name, promise);
-let goodsReducer = goodsReducerSlice.reducer;
-export { goodsReducer, actionGoodFindOne, actionGoodFind, actionGoodsCount,  getCurrentGood }

+ 6 - 1
src/reducers/frontEndReducer.js

@@ -104,6 +104,11 @@ const setCurrentGood = (state, id) => {
     return state[currentGood] = { payload: id };
 }
 
+const getGoodsCount = state => {
+    let result = state.frontend.goods.goodsCount?.payload ?? 0;
+    return result;
+}
+
 
 export { frontEndReducer, actionSetSidebar, actionSetOrdersPaging, actionSetOrderSearch, actionSetGoodsPaging, actionSetGoodsSearch };
-export { getCurrentCategory, getCurrentGood, actionSetCurrentCategory, actionSetCurrentGood }
+export { getCurrentCategory, getCurrentGood, actionSetCurrentCategory, actionSetCurrentGood, getGoodsCount }

+ 1 - 1
src/reducers/index.js

@@ -3,7 +3,7 @@ export { authApiReducer, authReducer, authApiReducerPath, loginApi, authReducerP
 export { cartReducer, actionAddGoodToCart, actionDeleteGoodFromCart, actionRestoreCart, actionClearCart, getCart, } from "./cartReducer";
 export { cartGoodsReducer, actionLoadCart } from "./cartGoodsReducer";
 export { localStoredReducer, } from "./localStoredReducer";
-export { frontEndReducer, getCurrentCategory, getCurrentGood } from "./frontEndReducer";
+export { frontEndReducer, getCurrentCategory, actionSetGoodsPaging, actionSetOrdersPaging, getCurrentGood, getGoodsCount } from "./frontEndReducer";
 export { useGetRootCategoriesQuery, useGetCategoryByIdQuery } from './categoryReducer';
 export { actionFindOrders, actionOrdersCount, actionPlaceOrder } from './ordersReducer';
 export { goodsApi, useGetGoodByIdQuery, useGetGoodsCountQuery, useGetGoodsQuery } from './goodsReducer';