-
Notifications
You must be signed in to change notification settings - Fork 312
/
DiscountSlider.jsx
123 lines (116 loc) · 3.89 KB
/
DiscountSlider.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import Link from 'next/link'
import Image from 'next/image'
import { Swiper, SwiperSlide } from 'swiper/react'
import 'swiper/css'
import { DiscountProduct, ProductPrice, ResponsiveImage, Skeleton } from 'components'
import { useGetProductsQuery } from '@/store/services'
const DiscountSlider = props => {
//? Props
const { currentCategory } = props
const { products, isLoading } = useGetProductsQuery(
{
sort: 6,
category: currentCategory?.slug,
page_size: 15,
discount: true,
},
{
selectFromResult: ({ data, isLoading }) => ({
products: data?.data?.products,
isLoading,
}),
}
)
//? Render(s)
if (currentCategory) {
return (
<section
className="lg:rounded-xl lg:mx-3 py-2.5 flex lg:px-1"
style={{
background: `linear-gradient(${`${currentCategory.colors?.start},${currentCategory.colors?.end}`})`,
}}
>
<Swiper
watchSlidesProgress={true}
slidesPerView={2}
breakpoints={{
490: { width: 490, slidesPerView: 3 },
}}
>
{isLoading
? Array(10)
.fill('_')
.map((_, index) => (
<SwiperSlide
key={index}
className={`w-fit bg-white mx-0.5 py-6 ${
index === 0 ? 'rounded-l-lg' : index === 9 ? 'rounded-r-lg' : ''
} `}
>
<Skeleton.Items>
<Skeleton.Item
height=" h-32 lg:h-36"
width="w-32 lg:w-36"
animated="background"
className="rounded-md mx-auto"
/>
<Skeleton.Item
height="h-5"
width="w-32"
animated="background"
className="mt-4 mx-auto"
/>
<Skeleton.Item
height="h-5"
width="w-20"
animated="background"
className="mt-4 mx-auto"
/>
</Skeleton.Items>
</SwiperSlide>
))
: products?.map((product, index) => (
<SwiperSlide
key={product._id}
className={`w-fit bg-white mx-0.5 py-6 ${
index === 0 ? 'rounded-l-lg' : index === 9 ? 'rounded-r-lg' : ''
} `}
>
<Link href={`/products/${product._id}`}>
<article>
<ResponsiveImage
dimensions="w-32 h-32 lg:w-36 lg:h-36"
className=" mx-auto"
src={product.images[0].url}
alt={product.title}
/>
<div className="flex px-2 mt-1.5 justify-evenly gap-x-2 ">
<div>
<DiscountProduct discount={product.discount} />
</div>
<ProductPrice
inStock={product.inStock}
discount={product.discount}
price={product.price}
/>
</div>
</article>
</Link>
</SwiperSlide>
))}
<SwiperSlide className="py-10 flex-center flex-col">
<Image
src={currentCategory.image}
alt={currentCategory.name}
width={96}
height={96}
priority
/>
<div className=" text-white text-sm">查看全部</div>
</SwiperSlide>
</Swiper>
</section>
)
}
}
export default DiscountSlider