LetDiscover.js
8.83 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import Image from "next/image";
import React, { useEffect, useState } from "react";
import { zoomIn, slideFromRight } from "../animationvariants.js";
import { Swiper, SwiperSlide } from "swiper/react";
import { Navigation, Autoplay } from "swiper/modules";
import { motion } from "framer-motion";
// Import Swiper styles
import "swiper/css";
import "swiper/css/pagination";
import "swiper/css/navigation";
import { cleanImage } from "../../services/imageHandling.js";
import { useRouter } from "next/router.js";
import { Loader } from "react-bootstrap-typeahead";
import { useDispatch, useSelector } from "react-redux";
import { getSubCategoriesByCategoryId } from "../../redux/actions/categoriesAction.js";
import { getActivitiesByFilters, setActivityFilters } from "../../redux/actions/activityAction.js";
import SubCategoryChips from "./SubCategoryChips.js";
const LetDiscover = ({ categories }) => {
const { subCategories, loading } = useSelector(sate => sate.subCategories);
const { activityFilters } = useSelector(sate => sate.activityFilters);
const router = useRouter();
const dispatch = useDispatch();
const [activeIndex, setActiveIndex] = useState("All");
// const [loading, setloading] = useState(null);
console.log("categories", categories);
console.log("subCategories", subCategories);
console.log("activityFilters", activityFilters);
const handleTitleClick = ({ index, data }) => {
// setloading(true);
// Check if the clicked index is already active
if (activeIndex === index) {
return; // Do nothing if it's already active
}
// Toggle the active index if it's different from the clicked index
// console.log("activeIndex",activeIndex, index);
setActiveIndex(index);
// setloading(false);
};
// useEffect(() => {
// dispatch(getSubCategoriesByCategoryId(router.query.category));
// }, [router]);
useEffect(() => {
console.log("router.query.category", router.query.category);
if (router.query.category) {
dispatch(setActivityFilters({ filters: { category: Number(router.query.category), subCategories: [] } }));
setActiveIndex((parseInt(router.query.category)));
dispatch(getSubCategoriesByCategoryId(parseInt(router.query.category)));
dispatch(getActivitiesByFilters({ category: { id: { $eq: Number(router.query.category) } } }));
console.log("router >>", router.query.category);
setActiveIndex(Number(router.query.category))
}
}, []);
const [showCloseIcon, setShowCloseIcon] = useState({});
const handleToggleCloseIcon = index => {
setShowCloseIcon(prevShowCloseIcon => ({
...prevShowCloseIcon,
[index]: !prevShowCloseIcon[index]
}));
};
console.log("showCloseIcon", showCloseIcon);
return (
<>
<section className="let-discover-session let-discover-listing-session">
<div className="container-fluid">
<div className="row">
<div className="col-12">
{/* <motion.div variants={slideFromRight(0.4)} initial={"false"} whileInView={"show"} viewport={{ once: false, amount: 0.2 }}>
your text or div will come here
</motion.div> */}
<div className="head-btn">
<motion.div variants={slideFromRight(0.4)} initial={"false"} whileInView={"show"} viewport={{ once: false, amount: 0.2 }}>
<div className="head01">
<div className="title">Let’s </div>
<h2>Discover</h2>
</div>
</motion.div>
</div>
</div>
</div>
<div className="row">
<div className="col-12">
<div className="let-discover-carousal position-relative">
<Swiper
slidesPerView={3}
autoplay={false}
// autoplay={{
// delay: 9000,
// disableOnInteraction: false
// }}
spaceBetween={10}
navigation={{ nextEl: ".letdiscover-arrow-left", prevEl: ".letdiscover-arrow-right" }}
breakpoints={{
640: {
slidesPerView: 3,
spaceBetween: 20
},
768: {
slidesPerView: 4,
spaceBetween: 20
},
1024: {
slidesPerView: 10,
spaceBetween: 20
}
}}
modules={[Navigation, Autoplay]}
className="mySwiper01 mySwiper02"
>
<SwiperSlide>
<motion.div variants={zoomIn("left", 0.3)} initial={"false"} whileInView={"show"} viewport={{ once: false, amount: 0.2 }}>
<a
className={activeIndex == "All" ? "active" : ""}
onClick={() => {
dispatch(setActivityFilters({ filters: {} }));
handleTitleClick({ index: "All" });
}}
>
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src={"/images/discover/01.webp"} />
</span>
<div className="title">{"All"}</div>
</a>
</motion.div>
</SwiperSlide>
{categories &&
categories.data.map((data, index) => {
const isActive = activeIndex === data.id;
return (
<>
<SwiperSlide>
<motion.div variants={zoomIn("left", 0.3)} initial={"false"} whileInView={"show"} viewport={{ once: false, amount: 0.2 }}>
<a
className={isActive ? "active" : ""}
onClick={async () => {
// router.push(`?category=${data.id}`);
dispatch(setActivityFilters({ filters: { ...activityFilters, category: data.id, subCategories: [] } }));
dispatch(getSubCategoriesByCategoryId(data.id));
handleTitleClick({ index: data.id, data });
}}
>
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src={cleanImage(data?.attributes?.image?.data?.attributes)} />
</span>
<div className="title">{data.attributes.name}</div>
</a>
</motion.div>
</SwiperSlide>
</>
);
})}
</Swiper>
<div className="swiper-nav">
<div className="navbutton d-flex justify-content-between ">
<button className="letdiscover-arrow-right arrow">
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src="/images/icons/arrow-left.svg" />
</span>
</button>
<button className="letdiscover-arrow-left arrow">
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src="/images/icons/arrow-right.svg" />
</span>
</button>
</div>
</div>
</div>
</div>
</div>
<div className="row">
<div className="col-12 text-center">
{!loading ? (
<div className="sub-categories">
{activityFilters.category &&
subCategories &&
subCategories.data.map((data, index) => (
<SubCategoryChips key={index} data={data} />
// <a key={index} onClick={() => handleToggleCloseIcon(index)}>
// <span>{data.attributes.name}</span>
// {showCloseIcon[index] && (
// <span className="image-container">
// <Image layout="fill" alt="image" className="image" src="/images/icons/close-button.svg" />
// </span>
// )}
// </a>
))}
</div>
) : (
<Loader />
)}
</div>
</div>
</div>
</section>
</>
);
};
export default LetDiscover;