Skip to content

Commit

Permalink
ViewedProductsSkeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Kseniya committed Jun 17, 2024
1 parent 46e430e commit 5ed3f3b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.skeletonViewedProductsCard {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 160px;
height: 100%;
background-color: #f0f0f0;
border-radius: 8px;
overflow: hidden;
margin:0;

& > *:not(:last-child) {
margin-bottom: 8px;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FC } from 'react'
import Skeleton from 'react-loading-skeleton'
import 'react-loading-skeleton/dist/skeleton.css'

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

const ViewedProductsSkeleton: FC = () => {
return (
<div className={styles.skeletonViewedProductsCard}>
<Skeleton width="100%" height={240} />
</div>
)
}

export default ViewedProductsSkeleton
27 changes: 15 additions & 12 deletions src/widgets/ViewedProducts/ui/ViewedProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Scroll from '@/shared/ui/Scroll/Scroll'
import { ProductItem } from '@/widgets/ProductItem/ProductItem'

import { getViewedProductsFromStorage } from '../model/functions/functions'
import ViewedProductsSkeleton from '../ViewedProductsSkeleton/ViewedProductsSkeleton'

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

Expand All @@ -28,7 +29,7 @@ const ViewedProducts: FC<IViewedProductsProps> = ({ title, hasLabel }) => {
/*TODO по FSD нельзя использовать widget ProductItem в widget, нужно перенести ProductItem в features или entities*/
}
const productList = viewedProducts.map((item, index) => {
if (hasLabel && index > VIEWED_PRODUCTS_COUNT_ON_MAIN) return
if (hasLabel && index > VIEWED_PRODUCTS_COUNT_ON_MAIN) return null

return (
<ProductItem
Expand All @@ -50,17 +51,19 @@ const ViewedProducts: FC<IViewedProductsProps> = ({ title, hasLabel }) => {
})

return (
viewedProducts?.length !== 0 && (
<section className={styles.viewedproducts}>
<div className={styles.viewedproducts__header}>
<Heading className={styles.viewedproducts__title}>{title}</Heading>
{hasLabel && <span className={styles.viewedproducts__label}>Вы смотрели</span>}
</div>
<Scroll className={styles.viewedproducts__scroll} withManualGrip={true}>
{productList}
</Scroll>
</section>
)
<section className={styles.viewedproducts}>
<div className={styles.viewedproducts__header}>
<Heading className={styles.viewedproducts__title}>{title}</Heading>
{hasLabel && <span className={styles.viewedproducts__label}>Вы смотрели</span>}
</div>
<Scroll className={styles.viewedproducts__scroll} withManualGrip={true}>
{viewedProducts?.length !== 0
? productList
: Array.from({ length: VIEWED_PRODUCTS_COUNT_ON_MAIN }).map((_, index) => (
<ViewedProductsSkeleton key={index} />
))}
</Scroll>
</section>
)
}

Expand Down

0 comments on commit 5ed3f3b

Please sign in to comment.