ListingItems.js
5.02 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
import { Empty } from "antd";
import Image from "next/image";
import { useRouter } from "next/router";
import React, { useState } from "react";
import { Button } from "react-bootstrap";
import { Loader } from "react-bootstrap-typeahead";
import { useSelector } from "react-redux";
import { cleanImage } from "../../services/imageHandling";
import WishlistComponent from "../detail/WIshlistComponent";
import Pagination from "react-js-pagination";
const ListingItems = ({ allActivitiesData, loading, gridClass, totalCount }) => {
// const [gridClass, setGridClass] = useState('col-md-3');
const { endUser } = useSelector(state => state.endUser);
console.log("endUser", endUser);
const router = useRouter();
// console.log("router", router);
let { page = 1, location = "" } = router.query;
page = Number(page);
let queryParams;
if (typeof window !== "undefined") {
queryParams = new URLSearchParams(window.location.search);
}
const handlePagination = pageNumber => {
// This was the old way to do this, by doing this we were getting rid of the other query string parameters.
// router.push(`?page=${pageNumber}`);
// We have done this to take care of keeping the search filters in the query params
// when we end up changing the page number.
if (queryParams.has("page")) {
queryParams.set("page", pageNumber);
} else {
queryParams.append("page", pageNumber);
}
router.replace({
search: queryParams.toString()
});
};
return (
<>
{allActivitiesData && !allActivitiesData.data.length == 0 ? (
<div className="listing-items">
{!loading ? (
<div className="row">
{allActivitiesData &&
allActivitiesData.data.map(data => {
return (
<div className={gridClass}>
<div className="item">
<div className="browse-experiences-item">
<div className="img-wrapper">
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src={cleanImage(data.attributes?.image?.data?.attributes)} />
</span>
<div className="top-rated">Top Rated</div>
</div>
<div className="info">
<div className="top-name">
<div className="title">{data?.attributes?.name}</div>
<div className="rating-wishlist">
<div className="rating">
{data?.attributes?.rating}
<span className="image-container">
<Image layout="fill" alt="" className="image img-fluid" src="/images/icons/star.svg" />
</span>
</div>
{endUser && <WishlistComponent activityId={data.id} userId={endUser.id} />}
</div>
</div>
<div className="discription">
{data.discription} <a href="">Read More</a>
</div>
<div className="price">
${data?.attributes?.pricePerPerson} <span className="off">{data?.attributes?.off}% OFF</span>
</div>
<div className="detail">
<div className="">For 1 Night</div>
<div className="">Includes taxes & Fees</div>
</div>
<div className="explore-now">
<Button
onClick={() => {
router.push(`/activities/${data.id}`);
}}
variant="primary"
>
Explore Now
</Button>
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
) : (
<Loader />
)}
</div>
) : (
<Empty />
)}
<div className="row">
<div className="col-12">
<div className="load-more">
<Pagination
activePage={page}
itemsCountPerPage={12}
totalItemsCount={totalCount}
onChange={handlePagination}
nextPageText={">"}
prevPageText={"<"}
firstPageText={"<<"}
lastPageText={">>"}
itemClass="page-item"
linkClass="page-link"
></Pagination>
</div>
</div>
</div>
</>
);
};
export default ListingItems;