From dc28c792717e0694d6ac9bbe964a1afb75aee769 Mon Sep 17 00:00:00 2001 From: Soni Dhruv Date: Mon, 20 May 2024 15:47:30 +0530 Subject: [PATCH] added collections page --- src/Pages/Collections.jsx | 122 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/src/Pages/Collections.jsx b/src/Pages/Collections.jsx index ee4a936..7513396 100644 --- a/src/Pages/Collections.jsx +++ b/src/Pages/Collections.jsx @@ -1,9 +1,121 @@ -import React from 'react' +import React, { useState } from 'react'; +import './CSS/Collections.css'; + +const products = [ + { id: 1, name: 'T-shirt', price: 15, image: 'https://img.freepik.com/premium-psd/young-man-oversize-t-shirt-mockup-psd-template-your-design_34168-2869.jpg?w=740', tag: 'New', category: 'For Men', type: 'Clothing' }, + { id: 2, name: 'Jeans', price: 40, image: 'https://i.pinimg.com/564x/b7/b1/47/b7b147b7761899ad568d3e528459b2b1.jpg', category: 'For Men', type: 'Clothing' }, + { id: 3, name: 'Dress', price: 60, image: 'https://i.pinimg.com/564x/29/f9/81/29f9811257d1375916f40b9329d1e4f3.jpg', tag: 'New', category: 'For Women', type: 'Clothing' }, + { id: 4, name: 'Skirt', price: 25, image: 'https://i.pinimg.com/564x/04/ee/7c/04ee7ca804f30a32ee93253e0f4fa6e9.jpg', category: 'For Women', type: 'Clothing' }, + { id: 5, name: 'Dress', price: 60, image: 'https://i.pinimg.com/564x/e1/24/30/e124303a2d9ed4dbcb77937d3a975078.jpg', tag: 'New', category: 'For Women', type: 'Clothing' }, +]; const Collections = () => { + const [categoryFilter, setCategoryFilter] = useState(''); + const [detailsFilter, setDetailsFilter] = useState([]); + const [clothingFilter, setClothingFilter] = useState([]); + const [priceSort, setPriceSort] = useState('default'); + + const handleFilterChange = (filterType, value) => { + if (filterType === 'category') { + setCategoryFilter(value); + } else if (filterType === 'details') { + setDetailsFilter(prevState => + prevState.includes(value) ? prevState.filter(item => item !== value) : [...prevState, value] + ); + } else if (filterType === 'clothing') { + setClothingFilter(prevState => + prevState.includes(value) ? prevState.filter(item => item !== value) : [...prevState, value] + ); + } + }; + + const filteredProducts = products.filter(product => { + if (categoryFilter && product.category !== categoryFilter) return false; + if (clothingFilter.length && product.type === 'Clothing' && !clothingFilter.includes(product.name)) return false; + if (detailsFilter.length && product.tag && !detailsFilter.includes(product.tag)) return false; + return true; + }); + + const sortedProducts = [...filteredProducts].sort((a, b) => { + if (priceSort === 'low') return a.price - b.price; + if (priceSort === 'high') return b.price - a.price; + return 0; + }); + return ( -
Collections
- ) -} +
+
+

collection

+
+
+ +
+ {sortedProducts.map(product => ( +
+ {product.name} +

{product.name}

+

${product.price}

+ {product.originalPrice &&

${product.originalPrice}

} + {product.tag && {product.tag}} +
+ ))} +
+
+
+ ); +}; -export default Collections \ No newline at end of file +export default Collections;