Skip to content

Commit

Permalink
feat: back to home btn + route guard
Browse files Browse the repository at this point in the history
  • Loading branch information
Bran18 committed Nov 22, 2024
1 parent df2d9c3 commit 08920ea
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions frontend/app/marketplace/page.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -77,22 +78,42 @@ 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 (
<Sidebar>
<SidebarHeader className="p-6 border-b">
<h2 className="text-xl font-semibold">Filters</h2>
</SidebarHeader>
<SidebarContent className="p-6">
<div className="space-y-8">
{showHomeButton && (
<div className="mb-6">
<Button
variant="outline"
className="w-full flex items-center justify-center gap-2"
onClick={() => router.push("/")}
>
<Home className="h-4 w-4" />
Home
</Button>
</div>
)}
<div>
<h3 className="mb-2 text-lg font-medium">Price range</h3>
<Slider
min={0}
max={1500}
step={10}
value={priceRange}
onValueChange={setPriceRange}
onVolumeChange={setPriceRange}
className="mb-3"
/>
<div className="flex justify-between text-lg">
Expand All @@ -103,16 +124,20 @@ function SidebarComponent({ priceRange, setPriceRange, selectedCategories, handl
<div>
<h3 className="mb-2 text-lg font-medium">Categories</h3>
<div className="space-y-3">
{["Electronics", "Furniture", "Appliances", "Sports"].map((category) => (
<div key={category} className="flex items-center">
<Checkbox
id={category}
checked={selectedCategories.includes(category)}
onCheckedChange={() => handleCategoryChange(category)}
/>
<label htmlFor={category} className="ml-3 text-lg">{category}</label>
</div>
))}
{["Electronics", "Furniture", "Appliances", "Sports"].map(
(category) => (
<div key={category} className="flex items-center">
<Checkbox
id={category}
checked={selectedCategories.includes(category)}
onCheckedChange={() => handleCategoryChange(category)}
/>
<label htmlFor={category} className="ml-3 text-lg">
{category}
</label>
</div>
)
)}
</div>
</div>
</div>
Expand Down

0 comments on commit 08920ea

Please sign in to comment.