From 545e9fc5d21751a5ea7fd581324af054cd3439f2 Mon Sep 17 00:00:00 2001 From: Margarita Shumilina Date: Sun, 5 May 2024 20:22:13 +0300 Subject: [PATCH 1/3] #339-pagination --- package-lock.json | 89 ++++++++++++------- package.json | 1 + .../StoreProvider/config/StateSchema.ts | 2 + .../providers/StoreProvider/config/store.ts | 4 +- src/components/Dropdown/Dropdown.tsx | 16 +++- src/components/PageControls/PageControls.tsx | 16 +++- src/components/Pagination/Pagination.tsx | 4 +- .../Pagination/selectors/selectors.tsx | 3 + .../Pagination/slice/paginationSlice.tsx | 21 +++++ src/components/Pagination/types/types.ts | 3 + src/pages/ProductsPage/ProductsPage.tsx | 86 ++++++++++++++---- .../ProductsPage/services/getProducts.ts | 19 ++-- 12 files changed, 198 insertions(+), 66 deletions(-) create mode 100644 src/components/Pagination/selectors/selectors.tsx create mode 100644 src/components/Pagination/slice/paginationSlice.tsx create mode 100644 src/components/Pagination/types/types.ts diff --git a/package-lock.json b/package-lock.json index f4f90c29..1ae9e472 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "formik": "^2.4.5", "leaflet": "^1.9.4", "normalize-scss": "7.0.1", + "qs": "^6.12.1", "react": "18.2.0", "react-dom": "18.2.0", "react-input-mask": "^2.0.4", @@ -9350,6 +9351,21 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, + "node_modules/body-parser/node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/bonjour-service": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.1.1.tgz", @@ -11931,6 +11947,21 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, + "node_modules/express/node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -17075,11 +17106,11 @@ } }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.12.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz", + "integrity": "sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==", "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" @@ -20119,21 +20150,6 @@ "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", "dev": true }, - "node_modules/url/node_modules/qs": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.0.tgz", - "integrity": "sha512-trVZiI6RMOkO476zLGaBIzszOdFPnCCXHPG9kn0yuS1uz6xdVxPfZdB3vUig9pxPFDM9BRAgz/YUIVQ1/vuiUg==", - "dev": true, - "dependencies": { - "side-channel": "^1.0.6" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/use-callback-ref": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.1.tgz", @@ -27464,6 +27480,15 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "requires": { + "side-channel": "^1.0.4" + } } } }, @@ -29416,6 +29441,15 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "requires": { + "side-channel": "^1.0.4" + } } } }, @@ -33155,11 +33189,11 @@ } }, "qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.12.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz", + "integrity": "sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==", "requires": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" } }, "queue-microtask": { @@ -35400,15 +35434,6 @@ "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", "dev": true - }, - "qs": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.0.tgz", - "integrity": "sha512-trVZiI6RMOkO476zLGaBIzszOdFPnCCXHPG9kn0yuS1uz6xdVxPfZdB3vUig9pxPFDM9BRAgz/YUIVQ1/vuiUg==", - "dev": true, - "requires": { - "side-channel": "^1.0.6" - } } } }, diff --git a/package.json b/package.json index 25fa73a9..33bad374 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "formik": "^2.4.5", "leaflet": "^1.9.4", "normalize-scss": "7.0.1", + "qs": "^6.12.1", "react": "18.2.0", "react-dom": "18.2.0", "react-input-mask": "^2.0.4", diff --git a/src/app/providers/StoreProvider/config/StateSchema.ts b/src/app/providers/StoreProvider/config/StateSchema.ts index b9a47753..2900dae7 100644 --- a/src/app/providers/StoreProvider/config/StateSchema.ts +++ b/src/app/providers/StoreProvider/config/StateSchema.ts @@ -20,6 +20,7 @@ import { ICartEntitySchema } from '@/entities/CartEntity/model/types/types' import { IAboutUsSchema } from '@/pages/AboutUsPage/model/types/types' import { ICartSchema } from '@/pages/CartPage/model/types' import { IProductAmountStateSchema } from '@/features/CartEdit/model/types' +import { TNumberOfPageSchema } from '@/components/Pagination/types/types' export interface StateSchema { aboutUs: IAboutUsSchema @@ -46,6 +47,7 @@ export interface StateSchema { cartEntity: ICartEntitySchema categoryFilters: ICategoryFiltersSchema productAmount: IProductAmountStateSchema + pagination: TNumberOfPageSchema } export interface ThunkExtraArg { diff --git a/src/app/providers/StoreProvider/config/store.ts b/src/app/providers/StoreProvider/config/store.ts index f77005b7..10d31603 100644 --- a/src/app/providers/StoreProvider/config/store.ts +++ b/src/app/providers/StoreProvider/config/store.ts @@ -25,6 +25,7 @@ import { aboutUsReducer } from '@/pages/AboutUsPage/model/slice/aboutUsSlice' import { cartReducer } from '@/pages/CartPage/model/slice' import { cartEntityReducer } from '@/entities/CartEntity/model/slice/cartEntitySlice' import { productAmountReducer } from '@/features/CartEdit/model/slice/productAmountSlice' +import { paginationSliceReducer } from '@/components/Pagination/slice/paginationSlice' export type RootState = StateSchema @@ -52,7 +53,8 @@ const rootReducer: ReducersMapObject = { cartEntity: cartEntityReducer, cart: cartReducer, categoryFilters: categoryFiltersSliceReducer, - productAmount: productAmountReducer + productAmount: productAmountReducer, + pagination: paginationSliceReducer } export function createReduxStore(initialState: RootState) { diff --git a/src/components/Dropdown/Dropdown.tsx b/src/components/Dropdown/Dropdown.tsx index 1101be7b..b55b2937 100644 --- a/src/components/Dropdown/Dropdown.tsx +++ b/src/components/Dropdown/Dropdown.tsx @@ -8,6 +8,7 @@ interface DropdownProps extends React.HTMLProps { items: TSortOptions[] defaultItem?: string onSelect: React.ChangeEventHandler + changeValue?: string } /** @@ -15,8 +16,15 @@ interface DropdownProps extends React.HTMLProps { * @param {array} items - список элементов выпадающего списка для выбора; * @param {string} defaultItem - выбранный по умолчанию элемент списка; * @param {function} onSelect - функция, применяющая выбранное из списка значение; + * @param {string} changeValue - выбранное название фильтра; */ -export const Dropdown: React.FC = ({ items, defaultItem, onSelect, ...props }) => { +export const Dropdown: React.FC = ({ + items, + defaultItem, + onSelect, + changeValue, + ...props +}) => { const [selectedItem, setSelectedItem] = useState(defaultItem || '') const handleSelect = (e: ChangeEvent) => { @@ -26,7 +34,11 @@ export const Dropdown: React.FC = ({ items, defaultItem, onSelect } return ( - {items.map(item => (