InnerDetailsSubCategory.js
2.79 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
import Image from "next/image";
import Link from "next/link";
import React, { useState } from "react";
import { Col, Row } from "react-bootstrap";
import { useRouter } from "next/router";
import FilterButton from "../Common/FilterButton";
const InnerDetailsSubCategory = ({ products }) => {
const router = useRouter();
const { category, subCategory } = router.query;
const [showFilter, setShowFilter] = useState(false);
const [sort, setSort] = useState("");
if (!products || !category || !subCategory) return null;
const handleChange = (e) => {
setSort(e.target.value);
};
// Optional sorting
const sortedProducts = [...products].sort((a, b) => {
if (sort === "name-asc") return a.title.localeCompare(b.title);
if (sort === "name-desc") return b.title.localeCompare(a.title);
return 0;
});
return (
<section className="collection-m-section sec_padd">
<div className="custom_container">
{/* Header */}
<Row className="align-content-center">
<Col xs={6}>
<h3>
{subCategory
.split("-")
.map(w => w.charAt(0).toUpperCase() + w.slice(1))
.join(" ")}
</h3>
</Col>
<Col xs={6} className="d-flex justify-content-end">
<>
<FilterButton
// onClick={() => setShowFilter(true)}
/>
{/* {showFilter && (
<div className="filter-panel">
Filter Content Here
<button
onClick={() => setShowFilter(false)}
>
Close</button>
</div>
)} */}
</>
<select
className="sortby-select"
value={sort}
onChange={handleChange}
>
<option value="">Sort By</option>
<option value="name-asc">Name: A–Z</option>
<option value="name-desc">Name: Z–A</option>
</select>
</Col>
</Row>
{/* Products */}
<Row>
{sortedProducts.map((product) => (
<Col md={6} key={product.productSlug}>
<div className="collections-item">
<Link
href={`/collections/${category}/${subCategory}/${product.productSlug}`}
>
<Image
width={868}
height={560}
src={product.image}
alt={product.title}
/>
<div className="title">{product.title}</div>
</Link>
</div>
</Col>
))}
</Row>
</div>
</section>
);
};
export default InnerDetailsSubCategory;