From 08920eae30784e6805960540593a190ad096fd99 Mon Sep 17 00:00:00 2001 From: Bran18 Date: Thu, 21 Nov 2024 19:57:26 -0600 Subject: [PATCH 1/6] feat: back to home btn + route guard --- frontend/app/marketplace/page.tsx | 53 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 178d7d5..7a57c54 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -1,12 +1,13 @@ 'use client'; -import { useState, Dispatch, SetStateAction } from 'react'; +import { useState, type Dispatch, type SetStateAction } from 'react'; import { Slider } from "@/app/components/ui/slider"; import { Checkbox } from "@/app/components/ui/checkbox"; import { Button } from "@/app/components/ui/button"; import { Input } from "@/app/components/ui/input"; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/app/components/ui/card"; import { Sidebar, SidebarContent, SidebarHeader, SidebarProvider, SidebarTrigger } from "@/app/components/ui/sidebar"; -import { Search, Menu as HamIcon } from "lucide-react"; +import { Search, Menu as HamIcon, Home } from "lucide-react"; +import { usePathname, useRouter } from 'next/navigation'; interface Product { id: number; @@ -77,7 +78,15 @@ export default function Marketplace() { ); } -function SidebarComponent({ priceRange, setPriceRange, selectedCategories, handleCategoryChange }: SidebarComponentProps) { +function SidebarComponent({ + priceRange, + setPriceRange, + selectedCategories, + handleCategoryChange, +}: SidebarComponentProps) { + const pathname = usePathname(); + const router = useRouter(); + const showHomeButton = pathname?.includes("/marketplace"); return ( @@ -85,6 +94,18 @@ function SidebarComponent({ priceRange, setPriceRange, selectedCategories, handl
+ {showHomeButton && ( +
+ +
+ )}

Price range

@@ -103,16 +124,20 @@ function SidebarComponent({ priceRange, setPriceRange, selectedCategories, handl

Categories

- {["Electronics", "Furniture", "Appliances", "Sports"].map((category) => ( -
- handleCategoryChange(category)} - /> - -
- ))} + {["Electronics", "Furniture", "Appliances", "Sports"].map( + (category) => ( +
+ handleCategoryChange(category)} + /> + +
+ ) + )}
From 767c9cffa0e0d5a4fc222e9519f3dcc016fe8ad9 Mon Sep 17 00:00:00 2001 From: Bran18 Date: Thu, 21 Nov 2024 20:16:54 -0600 Subject: [PATCH 2/6] chore: typo + dev notes --- frontend/app/marketplace/page.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 7a57c54..8d9f154 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -86,6 +86,7 @@ function SidebarComponent({ }: SidebarComponentProps) { const pathname = usePathname(); const router = useRouter(); + // * Shows home button only on marketplace path but can be extended to other pages if needed const showHomeButton = pathname?.includes("/marketplace"); return ( @@ -113,7 +114,7 @@ function SidebarComponent({ max={1500} step={10} value={priceRange} - onVolumeChange={setPriceRange} + onValueChange={setPriceRange} className="mb-3" />
From 667c5a8e435855f6158ec0260ec0585ab6b11d35 Mon Sep 17 00:00:00 2001 From: Bran18 Date: Fri, 22 Nov 2024 08:28:28 -0600 Subject: [PATCH 3/6] feat: reposition home navigation btn --- frontend/app/marketplace/page.tsx | 47 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 8d9f154..4ab8290 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -84,10 +84,6 @@ function SidebarComponent({ selectedCategories, handleCategoryChange, }: SidebarComponentProps) { - const pathname = usePathname(); - const router = useRouter(); - // * Shows home button only on marketplace path but can be extended to other pages if needed - const showHomeButton = pathname?.includes("/marketplace"); return ( @@ -95,18 +91,6 @@ function SidebarComponent({
- {showHomeButton && ( -
- -
- )}

Price range

- - - +
+ + + + {showHomeButton && ( + + )} +
From 1c5bec7ae3f2a82197847b5d6a87e9bf577e99a6 Mon Sep 17 00:00:00 2001 From: Bran18 Date: Fri, 22 Nov 2024 08:39:25 -0600 Subject: [PATCH 4/6] chore: code formarting + type import --- frontend/app/marketplace/page.tsx | 421 +++++++++++++++--------------- 1 file changed, 215 insertions(+), 206 deletions(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 75ef981..e06e9d3 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -2,218 +2,228 @@ 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 { Menu as HamIcon, Search, ShoppingCart, Home } from "lucide-react"; -import { Dispatch, SetStateAction, useState } from "react"; +import { type Dispatch, type SetStateAction, useState } from "react"; import ImageCarousel from "../components/ui/image-carrousel"; -import { usePathname, useRouter } from 'next/navigation'; +import { usePathname, useRouter } from "next/navigation"; 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) { const pathname = usePathname(); const router = useRouter(); @@ -257,33 +267,32 @@ function HeaderComponent({ searchTerm, setSearchTerm }: HeaderComponentProps) { ); } - 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} + + +
+ ))} +
+
+ ); } From 26bf8bd3f5a18435c1da0dbbe6e42dcd2d282b2a Mon Sep 17 00:00:00 2001 From: Bran18 Date: Sat, 23 Nov 2024 09:22:27 -0600 Subject: [PATCH 5/6] fix: code formating --- frontend/app/marketplace/page.tsx | 317 +++++++++++++++--------------- 1 file changed, 161 insertions(+), 156 deletions(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index d59921b..5bbc5c3 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -18,10 +18,15 @@ import { SidebarTrigger, } from "@/app/components/ui/sidebar"; import { Slider } from "@/app/components/ui/slider"; -import { Dispatch, SetStateAction, useState } from "react"; import ImageCarousel from "../components/ui/image-carrousel"; import { usePathname, useRouter } from "next/navigation"; -import { Menu as HamIcon, MessageSquareMore, Search, ShoppingCart, Home } from "lucide-react"; +import { + Menu as HamIcon, + MessageSquareMore, + Search, + ShoppingCart, + Home, +} from "lucide-react"; import { type Dispatch, type SetStateAction, useState } from "react"; interface Product { @@ -49,81 +54,81 @@ interface ProductListProps { } 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() { @@ -176,53 +181,53 @@ function SidebarComponent({ 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) { @@ -269,36 +274,36 @@ function HeaderComponent({ searchTerm, setSearchTerm }: HeaderComponentProps) { } 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} +
+ + +
+
+
+ ))} +
+
+ ); } From 302db96a444e895831dcec73efeb4cfa22c5122d Mon Sep 17 00:00:00 2001 From: Bran18 Date: Sat, 23 Nov 2024 09:46:56 -0600 Subject: [PATCH 6/6] fix: responsive layout --- frontend/app/marketplace/page.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/app/marketplace/page.tsx b/frontend/app/marketplace/page.tsx index 5bbc5c3..eb6cb55 100644 --- a/frontend/app/marketplace/page.tsx +++ b/frontend/app/marketplace/page.tsx @@ -237,7 +237,7 @@ function HeaderComponent({ searchTerm, setSearchTerm }: HeaderComponentProps) { return (
-
+
)}
-
+
setSearchTerm(e.target.value)} - className="w-[16rem] h-[3rem]" + className="w-full h-8 pr-10" /> -