From 8710beb8b4f04aabf588fa6a556500bb277d7097 Mon Sep 17 00:00:00 2001 From: Kirill Kurentsov Date: Sun, 14 Jan 2024 21:54:01 +0300 Subject: [PATCH 1/3] =?UTF-8?q?api:=20=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF?= =?UTF-8?q?=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=20Header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/router/AppRouter/ui/AppRouter.tsx | 5 ++ src/components/header/header.module.scss | 2 + src/components/header/header.tsx | 75 +++++++++++------------ src/mockData/catalogListData.ts | 8 +++ src/shared/api/types.ts | 3 +- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/app/router/AppRouter/ui/AppRouter.tsx b/src/app/router/AppRouter/ui/AppRouter.tsx index 0566066e..416bf6a7 100644 --- a/src/app/router/AppRouter/ui/AppRouter.tsx +++ b/src/app/router/AppRouter/ui/AppRouter.tsx @@ -28,6 +28,11 @@ export const AppRouter = createBrowserRouter([ path: Routes.PRODUCTS_ID, element: }, + // Добавил как временную заглушку пока не будет страницы категории + { + path: Routes.CATEGORIES + '/:slug', + element: + }, { path: Routes.LOGIN, element: diff --git a/src/components/header/header.module.scss b/src/components/header/header.module.scss index 3de82d3a..d0ed339e 100644 --- a/src/components/header/header.module.scss +++ b/src/components/header/header.module.scss @@ -157,6 +157,8 @@ list-style-type: none; padding: 20px 40px 20px 20px; row-gap: 15px; + max-height: 320px; + overflow-y: scroll; } &__context-menu-item { diff --git a/src/components/header/header.tsx b/src/components/header/header.tsx index e3cb12ee..0036a75a 100644 --- a/src/components/header/header.tsx +++ b/src/components/header/header.tsx @@ -1,5 +1,5 @@ import { coreBaseData } from '@/mockData/coreBaseData' -import { useMemo } from 'react' +import { useEffect, useMemo, useState } from 'react' import classNames from 'classnames' import Logo from '../../shared/ui/logo/Logo' import ArrowIcon from '@/assets/icons/arrow.svg' @@ -8,16 +8,20 @@ import ContextMenuElement from '../ContextMenuElement/ContextMenuElement' import HeaderAccount from '../HeaderAccount/HeaderAccount' import { PHONE_NUMBER } from '@/shared/constants/constants' import { headerAccountData } from '@/mockData/headerAccountData' -import { catalogListData } from '@/mockData/catalogListData' import CatalogLink from '../CatalogLink/CatalogLink' import { Routes } from '@/shared/config/routerConfig/routes' -import { CatalogLinksId } from '@/shared/config/catalogLinks/catalogLinks' import Link from '@/shared/ui/Link/Link' import IconCategories from '@/assets/icons/IconCategories.svg' -import styles from './header.module.scss' import SearchProduct from '@/features/SearchProduct' +import { linkItems } from '@/mockData/catalogListData' +import type { TCategory } from '@/models/CategoryModel' +import { ApiRoutes } from '@/shared/api/types' +import styles from './header.module.scss' function Header() { + const [categories, setCategories] = useState([]) + const [displayedCategories, setDisplayedCategories] = useState([]) + const aboutUsNode = useMemo( () => (
    @@ -91,51 +95,47 @@ function Header() { const catalogNode = useMemo( () => (
      - {catalogListData.map((item, index) => ( -
    • - - {item.name} + {categories.map(category => ( +
    • + + {category.name}
    • ))}
    ), - [] + [categories] ) + useEffect(() => { + fetch(`${__API__}api/${ApiRoutes.CATEGORIES}`) + .then(response => response.json()) + .then(categories => { + setCategories(categories) + setDisplayedCategories(categories.filter((c: TCategory) => c.is_visible_on_main === true)) + }) + }, []) + return (