2025-03-14 16:14:10 -06:00
|
|
|
import { useState } from "react";
|
2025-03-29 17:28:09 -06:00
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
2025-03-14 16:14:10 -06:00
|
|
|
import UserDropdown from "./UserDropdown";
|
|
|
|
|
import { Search, Heart } from "lucide-react";
|
2025-03-05 22:30:52 -07:00
|
|
|
|
|
|
|
|
const Navbar = ({ onLogout, userName }) => {
|
2025-03-14 16:14:10 -06:00
|
|
|
const [searchQuery, setSearchQuery] = useState("");
|
2025-03-29 17:28:09 -06:00
|
|
|
const navigate = useNavigate();
|
2025-03-14 16:14:10 -06:00
|
|
|
|
2025-03-05 22:30:52 -07:00
|
|
|
const handleSearchChange = (e) => {
|
|
|
|
|
setSearchQuery(e.target.value);
|
|
|
|
|
};
|
2025-03-14 16:14:10 -06:00
|
|
|
|
2025-03-05 22:30:52 -07:00
|
|
|
const handleSearchSubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
2025-03-29 17:28:09 -06:00
|
|
|
|
|
|
|
|
// if (!searchQuery.trim()) return;
|
|
|
|
|
|
|
|
|
|
// Navigate to search page with query
|
|
|
|
|
navigate({
|
|
|
|
|
pathname: "/search",
|
|
|
|
|
search: `?name=${encodeURIComponent(searchQuery)}`,
|
|
|
|
|
});
|
2025-03-05 22:30:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<nav className="bg-white shadow-sm border-b border-gray-200">
|
|
|
|
|
<div className="container mx-auto px-4">
|
|
|
|
|
<div className="flex items-center justify-between h-16">
|
|
|
|
|
{/* Logo */}
|
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
|
<Link to="/" className="flex items-center">
|
2025-03-14 16:14:10 -06:00
|
|
|
<img
|
|
|
|
|
src="/icon/icon-512.png"
|
|
|
|
|
alt="Campus Plug"
|
|
|
|
|
className="h-8 px-2"
|
|
|
|
|
/>
|
2025-04-18 10:43:41 -06:00
|
|
|
<span className="hidden md:block text-emerald-600 font-bold text-xl">
|
2025-03-14 16:14:10 -06:00
|
|
|
Campus Plug
|
|
|
|
|
</span>
|
2025-03-05 22:30:52 -07:00
|
|
|
</Link>
|
|
|
|
|
</div>
|
2025-03-14 16:14:10 -06:00
|
|
|
|
2025-03-05 22:30:52 -07:00
|
|
|
{/* Search Bar */}
|
|
|
|
|
<div className="flex-1 max-w-2xl px-4">
|
|
|
|
|
<form onSubmit={handleSearchSubmit} className="w-full">
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
2025-04-15 00:18:19 -06:00
|
|
|
placeholder="Search for anything..."
|
2025-04-18 10:37:19 -06:00
|
|
|
className="w-full p-2 pl-10 pr-4 border border-gray-300 focus:outline-none focus:border-[#ed7f30]-500 focus:ring-1 focus:ring-[#ed7f30]-500"
|
2025-03-05 22:30:52 -07:00
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={handleSearchChange}
|
|
|
|
|
/>
|
|
|
|
|
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
|
|
|
|
<Search className="h-5 w-5 text-gray-400" />
|
|
|
|
|
</div>
|
2025-03-29 17:28:09 -06:00
|
|
|
<button
|
|
|
|
|
type="submit"
|
2025-04-18 10:37:19 -06:00
|
|
|
className="absolute inset-y-0 right-0 flex items-center px-3 text-gray-500 hover:text-[#ed7f30]-500"
|
2025-03-29 17:28:09 -06:00
|
|
|
>
|
|
|
|
|
Search
|
|
|
|
|
</button>
|
2025-03-05 22:30:52 -07:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
2025-03-14 16:14:10 -06:00
|
|
|
|
2025-03-05 22:30:52 -07:00
|
|
|
{/* User Navigation */}
|
|
|
|
|
<div className="flex items-center space-x-4">
|
|
|
|
|
{/* Favorites Button */}
|
2025-03-14 16:14:10 -06:00
|
|
|
<Link
|
|
|
|
|
to="/favorites"
|
2025-04-18 10:37:19 -06:00
|
|
|
className="p-2 text-gray-600 hover:text-[#ed7f30]-600"
|
2025-03-14 16:14:10 -06:00
|
|
|
>
|
2025-03-05 22:30:52 -07:00
|
|
|
<Heart className="h-6 w-6" />
|
|
|
|
|
</Link>
|
2025-03-29 17:28:09 -06:00
|
|
|
|
2025-03-05 22:30:52 -07:00
|
|
|
{/* User Profile */}
|
|
|
|
|
<UserDropdown onLogout={onLogout} userName={userName} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-14 16:14:10 -06:00
|
|
|
export default Navbar;
|