diff --git a/frontend/app/components/marketplace/filters.tsx b/frontend/app/components/marketplace/filters.tsx index 9fdd799..e7723f3 100644 --- a/frontend/app/components/marketplace/filters.tsx +++ b/frontend/app/components/marketplace/filters.tsx @@ -1,14 +1,23 @@ "use client"; -import { Checkbox, Slider } from "@radix-ui/themes"; -import { useState } from "react"; +import { Checkbox } from "../ui/checkbox"; +import { Slider } from "../ui/slider"; -import { SidebarContent, SidebarHeader } from "@/app/components/ui/sidebar"; - -const Filters = () => { - const [priceRange, setPriceRange] = useState<[number, number]>([0, 1500]); - const [selectedCategories, setSelectedCategories] = useState([]); +interface FiltersProps { + priceRange: [number, number]; + setPriceRange: (value: [number, number]) => void; + selectedCategories: string[]; + setSelectedCategories: ( + value: string[] | ((prev: string[]) => string[]), + ) => void; +} +const Filters: React.FC = ({ + priceRange, + setPriceRange, + selectedCategories, + setSelectedCategories, +}) => { const handleCategoryChange = (category: string) => { setSelectedCategories((prev) => prev.includes(category) @@ -19,49 +28,41 @@ const Filters = () => { return ( <> - -

Filters

-
- -
-
-

Price range

- - setPriceRange(value as [number, number]) - } - className="mb-3" - /> -
- ${priceRange[0]} - ${priceRange[1]} -
-
-
-

Categories

-
- {["Electronics", "Furniture", "Appliances", "Sports"].map( - (category) => ( -
- handleCategoryChange(category)} - /> - -
- ), - )} -
+

Filters

+
+
+

Price Range

+ +
+ ${priceRange[0]} + ${priceRange[1]}
- + +
+

Categories

+ {["Electronics", "Furniture", "Appliances", "Sports"].map( + (category) => ( +
+ handleCategoryChange(category)} + /> + +
+ ), + )} +
+
); }; diff --git a/frontend/app/marketplace/[productId]/page.tsx b/frontend/app/marketplace/[productId]/page.tsx index 7801153..118ee87 100644 --- a/frontend/app/marketplace/[productId]/page.tsx +++ b/frontend/app/marketplace/[productId]/page.tsx @@ -1,6 +1,6 @@ import { Share2, ShoppingCart, Star } from "lucide-react"; -import Images from "@/app/components/products/images"; +import Images from "@/app/components/products/Images"; import SubHeader from "@/app/components/shared/sub-header"; import { Button } from "@/app/components/ui/button"; import { products } from "@/constants/testDataProduct"; diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 9525234..2db7a54 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -7,6 +7,7 @@ import { useState } from "react"; import AddProductModal from "@/app/components/marketplace/add-product-modal"; import BreadcrumbNavigation from "@/app/components/marketplace/breadcrumb-navigation"; +import Filters from "@/app/components/marketplace/filters"; import { ProductsPagination } from "@/app/components/marketplace/products-pagination"; import { Button } from "@/app/components/ui/button"; import { @@ -20,15 +21,16 @@ import { products } from "@/constants/testDataProduct"; export default function ProductList() { const [showModal, setShowModal] = useState(false); - // const filteredProducts = products.filter( - // (product) => - // (searchTerm === "" || - // product.name.toLowerCase().includes(searchTerm.toLowerCase())) && - // (selectedCategories.length === 0 || - // selectedCategories.includes(product.category)) && - // product.price >= priceRange[0] && - // product.price <= priceRange[1] - // ); + const [priceRange, setPriceRange] = useState<[number, number]>([0, 1500]); + const [selectedCategories, setSelectedCategories] = useState([]); + + const filteredProducts = products.filter( + (product) => + product.price >= priceRange[0] && + product.price <= priceRange[1] && + (selectedCategories.length === 0 || + selectedCategories.includes(product.category)), + ); return (
@@ -41,50 +43,64 @@ export default function ProductList() {
-
- {products?.map((product) => ( - - -
+
+ {/* Filters */} + + + {/* Product List */} +
+ {filteredProducts.map((product) => ( + + +
+ + {product.images[0].alt} + +
+

+ {product.category} +

- {product.images[0].alt} + + {product.name} + -
-

- {product.category} -

- - - {product.name} - - -
- - ${product.price} - - - - - -
- ))} + + + ${product.price} + + + + + + + ))} +
+ setShowModal(false)} />