diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index e75c234..eb6cb55 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -2,289 +2,312 @@ import { Button } from "@/app/components/ui/button"; import { - Card, - CardContent, - CardFooter, - CardHeader, - CardTitle, + Card, + CardContent, + CardFooter, + CardHeader, + CardTitle, } from "@/app/components/ui/card"; import { Checkbox } from "@/app/components/ui/checkbox"; import { Input } from "@/app/components/ui/input"; import { - Sidebar, - SidebarContent, - SidebarHeader, - SidebarProvider, - SidebarTrigger, + Sidebar, + SidebarContent, + SidebarHeader, + SidebarProvider, + SidebarTrigger, } from "@/app/components/ui/sidebar"; import { Slider } from "@/app/components/ui/slider"; +import ImageCarousel from "../components/ui/image-carrousel"; +import { usePathname, useRouter } from "next/navigation"; import { - Menu as HamIcon, - MessageSquareMore, - Search, - ShoppingCart, + Menu as HamIcon, + MessageSquareMore, + Search, + ShoppingCart, + Home, } from "lucide-react"; -import { Dispatch, SetStateAction, useState } from "react"; -import ImageCarousel from "../components/ui/image-carrousel"; +import { type Dispatch, type SetStateAction, useState } from "react"; interface Product { - id: number; - images: { src: string; alt: string }[]; - name: string; - price: number; - category: string; + id: number; + images: { src: string; alt: string }[]; + name: string; + price: number; + category: string; } interface SidebarComponentProps { - priceRange: [number, number]; - setPriceRange: Dispatch>; - selectedCategories: string[]; - handleCategoryChange: (category: string) => void; + priceRange: [number, number]; + setPriceRange: Dispatch>; + selectedCategories: string[]; + handleCategoryChange: (category: string) => void; } interface HeaderComponentProps { - searchTerm: string; - setSearchTerm: Dispatch>; + searchTerm: string; + setSearchTerm: Dispatch>; } interface ProductListProps { - products: Product[]; + products: Product[]; } const products: Product[] = [ - { - id: 1, - name: "MacBook Pro 14", - price: 1299, - category: "Electronics", - images: [ - { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, - { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, - { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, - ], - }, - { - id: 2, - name: "Samsung Galaxy S24 FE", - price: 699, - category: "Electronics", - images: [ - { - src: "/images/samsung-galaxy-s24-fe.webp", - alt: "Samsung Galaxy S24 FE", - }, - { - src: "/images/samsung-galaxy-s24-fe.webp", - alt: "Samsung Galaxy S24 FE", - }, - { - src: "/images/samsung-galaxy-s24-fe.webp", - alt: "Samsung Galaxy S24 FE", - }, - ], - }, - { - id: 3, - name: "Ergonomic Chair", - price: 299, - category: "Furniture", - images: [ - { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, - { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, - { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, - ], - }, - { - id: 4, - name: "Coffee Maker", - price: 89, - category: "Appliances", - images: [ - { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, - { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, - { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, - ], - }, - { - id: 5, - name: "Running Shoes", - price: 129, - category: "Sports", - images: [ - { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, - { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, - { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, - ], - }, - { - id: 6, - name: "Wireless Earbuds", - price: 159, - category: "Electronics", - images: [ - { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, - { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, - { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, - ], - }, + { + id: 1, + name: "MacBook Pro 14", + price: 1299, + category: "Electronics", + images: [ + { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, + { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, + { src: "/images/macbook-pro-14.webp", alt: "MacBook Pro 14" }, + ], + }, + { + id: 2, + name: "Samsung Galaxy S24 FE", + price: 699, + category: "Electronics", + images: [ + { + src: "/images/samsung-galaxy-s24-fe.webp", + alt: "Samsung Galaxy S24 FE", + }, + { + src: "/images/samsung-galaxy-s24-fe.webp", + alt: "Samsung Galaxy S24 FE", + }, + { + src: "/images/samsung-galaxy-s24-fe.webp", + alt: "Samsung Galaxy S24 FE", + }, + ], + }, + { + id: 3, + name: "Ergonomic Chair", + price: 299, + category: "Furniture", + images: [ + { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, + { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, + { src: "/images/ergonomic-chair.jpg", alt: "Ergonomic Chair" }, + ], + }, + { + id: 4, + name: "Coffee Maker", + price: 89, + category: "Appliances", + images: [ + { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, + { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, + { src: "/images/coffee-maker.webp", alt: "Coffee Maker" }, + ], + }, + { + id: 5, + name: "Running Shoes", + price: 129, + category: "Sports", + images: [ + { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, + { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, + { src: "/images/running-shoes.jpg", alt: "Running Shoes" }, + ], + }, + { + id: 6, + name: "Wireless Earbuds", + price: 159, + category: "Electronics", + images: [ + { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, + { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, + { src: "/images/wireless-earbuds.jpg", alt: "Wireless Earbuds" }, + ], + }, ]; export default function Marketplace() { - const [priceRange, setPriceRange] = useState<[number, number]>([0, 1500]); - const [selectedCategories, setSelectedCategories] = useState([]); - const [searchTerm, setSearchTerm] = useState(""); + const [priceRange, setPriceRange] = useState<[number, number]>([0, 1500]); + const [selectedCategories, setSelectedCategories] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); - const handleCategoryChange = (category: string) => { - setSelectedCategories((prev) => - prev.includes(category) - ? prev.filter((c) => c !== category) - : [...prev, category], - ); - }; + const handleCategoryChange = (category: string) => { + setSelectedCategories((prev) => + prev.includes(category) + ? prev.filter((c) => c !== category) + : [...prev, category] + ); + }; - 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 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] + ); - return ( - -
- -
- - -
-
-
- ); + return ( + +
+ +
+ + +
+
+
+ ); } function SidebarComponent({ - priceRange, - setPriceRange, - selectedCategories, - handleCategoryChange, + priceRange, + setPriceRange, + selectedCategories, + handleCategoryChange, }: SidebarComponentProps) { - 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)} - /> - -
- ), - )} -
-
-
-
-
- ); + 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)} + /> + +
+ ) + )} +
+
+
+
+
+ ); } function HeaderComponent({ searchTerm, setSearchTerm }: HeaderComponentProps) { - return ( -
- - - -
- setSearchTerm(e.target.value)} - className="w-full h-[3rem] md:w-[16rem]" - /> - -
-
- ); + const pathname = usePathname(); + const router = useRouter(); + const showHomeButton = pathname?.includes("/marketplace"); + + return ( +
+
+ + + + {showHomeButton && ( + + )} +
+
+ setSearchTerm(e.target.value)} + className="w-full h-8 pr-10" + /> + +
+
+ ); } function ProductList({ products }: ProductListProps) { - return ( -
-

Products

-
- {products?.map((product) => ( - - - - - {product.name} - - - -

{product.category}

-
- - ${product.price} -
- - -
-
-
- ))} -
-
- ); + return ( +
+

Products

+
+ {products?.map((product) => ( + + + + + {product.name} + + + +

{product.category}

+
+ + ${product.price} +
+ + +
+
+
+ ))} +
+
+ ); }