Skip to content

Commit

Permalink
Merge pull request #324 from Studio-Yandex-Practicum/enhancement_314_…
Browse files Browse the repository at this point in the history
…product_page

Добавил breadcrumbs на страницу товара. Немного поправил компонент br…
  • Loading branch information
kirill-k88 authored Apr 19, 2024
2 parents 8ff0f59 + 5c5a55a commit 205b5ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/pages/ProductPage/ProductPage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.pageDescriptor {
width: 100%;
display: flex;
flex-direction: column;
gap: 10px;
}
14 changes: 12 additions & 2 deletions src/pages/ProductPage/ProductPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { useParams } from 'react-router'

import { StateSchema } from '@/app/providers/StoreProvider'
import { AppDispatch } from '@/app/providers/StoreProvider/config/store'
import { PageDescription } from '@/components/PageDescription/PageDescription'
import WrapperForMainContent from '@/components/WrapperForMainContent/WrapperForMainContent'
import Breadcrumbs from '@/shared/ui/Breadcrumbs/Breadcrumbs'
import Heading from '@/shared/ui/Heading/Heading'
import Advantages from '@/widgets/Advantages/ui/Advantages/Advantages'
import { Product } from '@/widgets/Product/Product'
import { ProductInfo } from '@/widgets/ProductInfo/ProductInfo'
import { ViewedProducts } from '@/widgets/ViewedProducts/ViewedProducts'

import { addToViewedProducts } from './model/functions/functions'
import { getProduct } from './model/slice/productSlice'
import styles from './ProductPage.module.scss'

/**
* Страница с выбранным товаром.
Expand All @@ -23,6 +25,11 @@ export const ProductPage = () => {
const productStore = useSelector((store: StateSchema) => store.product)
const { slug } = useParams()

const links = [
{ heading: 'Главная', href: '/' },
{ heading: productStore.product.name, href: '' }
]

useEffect(() => {
if (slug) dispatch(getProduct(slug))
}, [slug])
Expand All @@ -34,7 +41,10 @@ export const ProductPage = () => {
return (
<>
<WrapperForMainContent>
<PageDescription count={-1} heading={productStore.product.name} />
<div className={styles.pageDescriptor}>
<Heading>{productStore.product.name}</Heading>
<Breadcrumbs links={links} />
</div>
<Product product={productStore.product} />
<ProductInfo description={productStore.product.description} />
<Advantages />
Expand Down
11 changes: 8 additions & 3 deletions src/shared/ui/Breadcrumbs/Breadcrumbs.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@use '../../styles/utils/variables' as var;

.breadcrumbs {
display: flex;
display: flex;
}

.link {
color: var.$subtitle-color;
}
color: var.$subtitle-color;
transition: color 0.3s;

&:hover {
color: var.$theme-secondary-color;
}
}
4 changes: 2 additions & 2 deletions src/shared/ui/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const Breadcrumbs: FC<TBreadcrumbsProps> = ({ links }) => {
(index !== links.length - 1 && (
<Subheading>
<Link key={link.href} to={link.href} className={styles.link}>
{link.heading}{' '}
{link.heading}
</Link>
<span>{` / `}</span>
<span>&nbsp;&#47;&nbsp;</span>
</Subheading>
)) || <Subheading key={link.href}>{link.heading}</Subheading>
)
Expand Down

0 comments on commit 205b5ba

Please sign in to comment.