Skip to content

Commit 6b5b16c

Browse files
feat: implement responsive Navbar component and integrate into App
1 parent 2e2c37b commit 6b5b16c

File tree

3 files changed

+118
-19
lines changed

3 files changed

+118
-19
lines changed

frontend/package-lock.json

Lines changed: 2 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import SignIn from "./pages/Signin";
88
import Browse from "./pages/Browse";
99
import Sell from "./pages/Sell";
1010
import ProductDetailsPage from "./pages/ProductDetail";
11+
import Navbar from "./components/Navbar";
1112
const queryClient = new QueryClient();
1213

1314
const App = () => (
1415
<QueryClientProvider client={queryClient}>
1516
<TooltipProvider>
1617
<Toaster />
18+
1719
<BrowserRouter>
20+
<Navbar />
21+
<div className="pt-[50px]">
22+
1823
<Routes>
1924
<Route path="/" element={<Index />} />
2025
<Route path="/signup" element={<SignUp />} />
@@ -23,6 +28,7 @@ const App = () => (
2328
<Route path="/product/:id" element={<ProductDetailsPage />} />
2429
<Route path="/sell" element={<Sell />} />
2530
</Routes>
31+
</div>
2632
</BrowserRouter>
2733
</TooltipProvider>
2834
</QueryClientProvider>

frontend/src/components/Navbar.tsx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import React, { useState } from "react";
2+
import { Link, useNavigate, useLocation } from "react-router-dom";
3+
import { Button } from "@/components/ui/button";
4+
import { Menu, X } from "lucide-react";
5+
6+
const Navbar: React.FC = () => {
7+
const [isOpen, setIsOpen] = useState(false);
8+
const navigate = useNavigate();
9+
const location = useLocation();
10+
11+
const handleNavClick = (path: string) => {
12+
navigate(path);
13+
setIsOpen(false);
14+
};
15+
16+
const navLinks = [
17+
{ name: "Home", path: "/" },
18+
{ name: "Browse", path: "/browse" },
19+
{ name: "Sell", path: "/sell" },
20+
];
21+
22+
return (
23+
<nav className="w-full bg-white/80 backdrop-blur-md shadow-sm fixed top-0 left-0 z-50">
24+
<div className="container mx-auto px-6 py-3 flex items-center justify-between">
25+
<Link
26+
to="/"
27+
className="text-2xl font-extrabold text-blue-800 tracking-tight hover:opacity-80 transition"
28+
>
29+
UniLoot
30+
</Link>
31+
32+
<div className="hidden md:flex items-center gap-8">
33+
{navLinks.map((link) => (
34+
<button
35+
key={link.name}
36+
onClick={() => handleNavClick(link.path)}
37+
className={`text-base font-semibold transition-colors duration-300 ${
38+
location.pathname === link.path
39+
? "text-blue-800"
40+
: "text-gray-700 hover:text-blue-800"
41+
}`}
42+
>
43+
{link.name}
44+
</button>
45+
))}
46+
</div>
47+
48+
<div className="hidden md:flex items-center gap-3">
49+
<Button
50+
variant="outline"
51+
className="border-2 border-blue-800 text-blue-800 hover:bg-blue-800 hover:text-white transition"
52+
onClick={() => handleNavClick("/signin")}
53+
>
54+
Sign In
55+
</Button>
56+
<Button
57+
className="bg-blue-800 text-white hover:bg-blue-900 transition"
58+
onClick={() => handleNavClick("/signup")}
59+
>
60+
Sign Up
61+
</Button>
62+
</div>
63+
64+
<button
65+
onClick={() => setIsOpen(!isOpen)}
66+
className="md:hidden text-blue-800 focus:outline-none"
67+
>
68+
{isOpen ? <X size={28} /> : <Menu size={28} />}
69+
</button>
70+
</div>
71+
72+
{isOpen && (
73+
<div className="md:hidden bg-white border-t border-gray-200 shadow-md">
74+
<div className="flex flex-col items-center py-4 space-y-4">
75+
{navLinks.map((link) => (
76+
<button
77+
key={link.name}
78+
onClick={() => handleNavClick(link.path)}
79+
className={`text-lg font-semibold ${
80+
location.pathname === link.path
81+
? "text-blue-800"
82+
: "text-gray-700 hover:text-blue-800"
83+
}`}
84+
>
85+
{link.name}
86+
</button>
87+
))}
88+
<div className="flex flex-col gap-2 pt-3 w-4/5">
89+
<Button
90+
variant="outline"
91+
className="border-2 border-blue-800 text-blue-800 hover:bg-blue-800 hover:text-white w-full"
92+
onClick={() => handleNavClick("/signin")}
93+
>
94+
Sign In
95+
</Button>
96+
<Button
97+
className="bg-blue-800 text-white hover:bg-blue-900 w-full"
98+
onClick={() => handleNavClick("/signup")}
99+
>
100+
Sign Up
101+
</Button>
102+
</div>
103+
</div>
104+
</div>
105+
)}
106+
</nav>
107+
);
108+
};
109+
110+
export default Navbar;

0 commit comments

Comments
 (0)