Skip to content

Commit

Permalink
Merge branch 'master' into enhancement_381_favorite_page
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-k88 committed May 18, 2024
2 parents 5617fe4 + e8a1516 commit f5fbbd2
Show file tree
Hide file tree
Showing 46 changed files with 701 additions and 208 deletions.
89 changes: 57 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/app/providers/StoreProvider/config/StateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IAboutUsSchema } from '@/pages/AboutUsPage/model/types/types'
import { ICartSchema } from '@/pages/CartPage/model/types'
import { IProductAmountStateSchema } from '@/features/CartEdit/model/types'
import { IFeedbackSchema } from '@/features/Reviews/model/types/types'
import { TNumberOfPageSchema } from '@/components/Pagination/types/types'

export interface StateSchema {
aboutUs: IAboutUsSchema
Expand All @@ -44,6 +45,7 @@ export interface StateSchema {
categoryFilters: ICategoryFiltersSchema
productAmount: IProductAmountStateSchema
feedbacks: IFeedbackSchema
pagination: TNumberOfPageSchema
}

export interface ThunkExtraArg {
Expand Down
4 changes: 3 additions & 1 deletion src/app/providers/StoreProvider/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { cartReducer } from '@/pages/CartPage/model/slice'
import { cartEntityReducer } from '@/entities/CartEntity/model/slice/cartEntitySlice'
import { productAmountReducer } from '@/features/CartEdit/model/slice/productAmountSlice'
import { feedbacksReducer } from '@/features/Reviews/model/slice/feedbacksSlice'
import { paginationSliceReducer } from '@/components/Pagination/slice/paginationSlice'

export type RootState = StateSchema

Expand All @@ -50,7 +51,8 @@ const rootReducer: ReducersMapObject<RootState> = {
cartEntity: cartEntityReducer,
cart: cartReducer,
categoryFilters: categoryFiltersSliceReducer,
productAmount: productAmountReducer
productAmount: productAmountReducer,
pagination: paginationSliceReducer
}

export function createReduxStore(initialState: RootState) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/router/AppRouter/ui/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const AppRouter = createBrowserRouter([
element: <ProductsPage /> // временная заглушка нужна страница со всеми брендами
},
{
path: Routes.CATEGORIES + '/all',
path: Routes.CATEGORIES,
element: <CategoryPage />
},
{
Expand Down
16 changes: 14 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ interface DropdownProps extends React.HTMLProps<HTMLSelectElement> {
items: TSortOptions[]
defaultItem?: string
onSelect: React.ChangeEventHandler<HTMLSelectElement>
changeValue?: string
}

/**
* Компонент для инпута - выпадающего списка.
* @param {array} items - список элементов выпадающего списка для выбора;
* @param {string} defaultItem - выбранный по умолчанию элемент списка;
* @param {function} onSelect - функция, применяющая выбранное из списка значение;
* @param {string} changeValue - выбранное название фильтра;
*/
export const Dropdown: React.FC<DropdownProps> = ({ items, defaultItem, onSelect, ...props }) => {
export const Dropdown: React.FC<DropdownProps> = ({
items,
defaultItem,
onSelect,
changeValue,
...props
}) => {
const [selectedItem, setSelectedItem] = useState<string>(defaultItem || '')

const handleSelect = (e: ChangeEvent<HTMLSelectElement>) => {
Expand All @@ -26,7 +34,11 @@ export const Dropdown: React.FC<DropdownProps> = ({ items, defaultItem, onSelect
}

return (
<select className={styles.select} value={selectedItem} onChange={handleSelect} {...props}>
<select
className={styles.select}
value={changeValue ? changeValue : selectedItem}
onChange={handleSelect}
{...props}>
{items.map(item => (
<option value={item.name} key={item.name}>
{item.name}
Expand Down
16 changes: 13 additions & 3 deletions src/components/PageControls/PageControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type TPageControls = {
handleSortChange: ChangeEventHandler<HTMLSelectElement>
itemPerPageOptions: TSortOptions[]
sortOptions: TSortOptions[]
changeValueToFilterProducts?: string
changeValueToQuantityProducts?: string
}

/**
Expand All @@ -30,20 +32,28 @@ type TPageControls = {
* @param {function} handleSortChange - функция управления порядком сортировки карточек;
* @param {array} itemPerPageOptions - текущее кол-во отображаемых карточек на странице;
* @param {array} sortOptions - текущий выбранный порядок сортировки карточек;
* @param {string} changeValueToFilterProducts - наименование выбранного фильтра товаров по Названию/Цене/Модели
* @param {string} changeValueToQuantityProducts - наименование выбранного фильтра товаров по количеству в листинге
*/
export const PageControls: FC<TPageControls> = ({
cardView,
handleCardViewChange,
handleItemsPerPageChange,
handleSortChange,
itemPerPageOptions,
sortOptions
sortOptions,
changeValueToFilterProducts,
changeValueToQuantityProducts
}) => {
return (
<div className={styles['page-controls']}>
<div className={styles.dropdowns}>
<Dropdown items={sortOptions} onSelect={handleSortChange} />
<Dropdown items={itemPerPageOptions} onSelect={handleItemsPerPageChange} />
<Dropdown items={sortOptions} onSelect={handleSortChange} changeValue={changeValueToFilterProducts} />
<Dropdown
items={itemPerPageOptions}
onSelect={handleItemsPerPageChange}
changeValue={changeValueToQuantityProducts}
/>
</div>
<ul className={styles['cards-controls']}>
<li
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react'
import { type FC } from 'react'

import styles from './Pagination.module.scss'

Expand Down
3 changes: 3 additions & 0 deletions src/components/Pagination/selectors/selectors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RootState } from '@/app/providers/StoreProvider/config/store'

export const selectNumberOfPage = (state: RootState) => state.pagination.numberOfPage
21 changes: 21 additions & 0 deletions src/components/Pagination/slice/paginationSlice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createSlice } from '@reduxjs/toolkit'

import type { TNumberOfPageSchema } from '@/components/Pagination/types/types'

const initialState: TNumberOfPageSchema = {
numberOfPage: 1
}

const paginationSlice = createSlice({
name: 'pagination',
initialState,
reducers: {
setNumberOfPage(state, action) {
state.numberOfPage = action.payload
}
}
})

export const { reducer: paginationSliceReducer } = paginationSlice

export const { setNumberOfPage } = paginationSlice.actions
3 changes: 3 additions & 0 deletions src/components/Pagination/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type TNumberOfPageSchema = {
numberOfPage: number
}
18 changes: 15 additions & 3 deletions src/entities/HeaderAccount/HeaderAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import styles from './headerAccount.module.scss'

export type HeaderAccountProps = {
isMenuModalOpen?: boolean
changeSearchModalState?: () => void
handleClose?: () => void
counter: number
total: string
Expand All @@ -35,12 +36,19 @@ const LazyLoginForm = lazy(() => import('@/features/login/index'))

/**
* Компонент хедера, показывающий блок аккаунта
* @param {boolean} isMenuModalOpen - состояние открытия модального окна;
* @param {boolean} isMenuModalOpen - состояние открытия модального окна меню;
* @param {boolean} changeSearchModalState - состояние открытия модального окна поиска;
* @param {function} handleClose - функция закрытия модального окна;
* @param {string} counter - счетчик количества товаров в корзине;
* @param {string} total - полная стоимость;
*/
const HeaderAccount: FC<HeaderAccountProps> = ({ isMenuModalOpen, handleClose, counter, total }) => {
const HeaderAccount: FC<HeaderAccountProps> = ({
isMenuModalOpen,
changeSearchModalState,
handleClose,
counter,
total
}) => {
const [isModalOpen, setIsModalOpen] = useState(false)
const [isModalClosing, setIsModalClosing] = useState(false)

Expand Down Expand Up @@ -91,7 +99,11 @@ const HeaderAccount: FC<HeaderAccountProps> = ({ isMenuModalOpen, handleClose, c
className={
isScreenLg || isMenuModalOpen ? `${styles.headerAccount}` : `${styles.headerAccount__mobile}`
}>
{isScreenLg || isMenuModalOpen ? null : <SearchIcon className={styles.headerAccount__icon} />}
{isScreenLg || isMenuModalOpen ? null : (
<Button onClick={changeSearchModalState} className={styles.headerAccount__search}>
<SearchIcon className={styles.headerAccount__icon} />
</Button>
)}
<li>
{/* Временная реализация
TODO заменить на дропдаун на ховер в контекстном меню добавить пункт-кнопку для разлогина пока висит на иконке */}
Expand Down
5 changes: 5 additions & 0 deletions src/entities/HeaderAccount/headerAccount.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,9 @@
margin-left: 10px;
margin-right: 10px;
}

&__search {
margin: 0;
padding: 0;
}
}
2 changes: 2 additions & 0 deletions src/entities/ModalHeading/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ModalHeading from './ui/ModalHeading'
export default ModalHeading
Loading

0 comments on commit f5fbbd2

Please sign in to comment.