2025-03-19 19:20:18 +00:00
|
|
|
"use client";
|
|
|
|
|
import { useState } from "react";
|
2025-03-10 13:27:47 +00:00
|
|
|
|
2025-03-19 19:20:18 +00:00
|
|
|
import AuthModal from "@/components/AuthModal";
|
|
|
|
|
import { usePathname } from "next/navigation";
|
2025-03-17 12:43:28 +00:00
|
|
|
import Link from "next/link";
|
2025-03-19 19:20:18 +00:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { FaRegUserCircle } from "react-icons/fa";
|
2025-03-17 13:21:02 +00:00
|
|
|
|
2025-03-19 19:20:18 +00:00
|
|
|
function NavbarButton({ name, href, dropdownItems }: { name: string; href: string; dropdownItems?: string[] }) {
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const isActive = dropdownItems ? dropdownItems.some((item) => pathname === `/${item.toLowerCase().replace(" ", "-")}`) : pathname === href;
|
2025-03-10 13:27:47 +00:00
|
|
|
|
2025-03-19 19:20:18 +00:00
|
|
|
return (
|
|
|
|
|
<button className="flex items-center justify-center px-2 py-4 relative group">
|
|
|
|
|
{dropdownItems ? (
|
|
|
|
|
<span className={`px-4 py-1.5 rounded-md transition-colors ${isActive ? "bg-neutral-200" : "group-hover:bg-neutral-200"}`}>{name}</span>
|
|
|
|
|
) : (
|
|
|
|
|
<Link href={href} className={`px-4 py-1.5 rounded-md transition-colors ${isActive ? "bg-neutral-200" : "hover:bg-neutral-200"}`}>
|
|
|
|
|
{name}
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
{dropdownItems && (
|
|
|
|
|
<div className="absolute hidden group-hover:block top-full left-1/2 -translate-x-1/2 w-40 bg-white border border-neutral-300 rounded-lg overflow-hidden shadow-lg z-40">
|
|
|
|
|
<ul>
|
|
|
|
|
{dropdownItems.map((item) => {
|
|
|
|
|
const itemHref = `/${item.toLowerCase().replace(" ", "-")}`;
|
|
|
|
|
const isDropdownActive = pathname === itemHref;
|
|
|
|
|
return (
|
|
|
|
|
<li key={item}>
|
|
|
|
|
<Link href={itemHref} className={`block px-4 py-2 hover:bg-neutral-100 ${isDropdownActive ? "bg-neutral-100" : ""}`}>
|
|
|
|
|
{item}
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-03-10 13:27:47 +00:00
|
|
|
|
2025-03-19 19:20:18 +00:00
|
|
|
export default function Navbar() {
|
|
|
|
|
const navOptions = useMemo(() => ["Earthquakes", "Observatories", "Warehouse", "Shop"], []);
|
|
|
|
|
// const navOptions = useMemo(() => ["Earthquakes"], []);
|
|
|
|
|
const aboutDropdown = ["Our Mission", "The Team", "Contact Us"];
|
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2025-03-10 13:27:47 +00:00
|
|
|
|
2025-03-19 19:20:18 +00:00
|
|
|
return (
|
|
|
|
|
<div className="flex sticky top-0 w-full h-14 z-40 font-medium bg-white">
|
|
|
|
|
<div className="my-1 flex aspect-square ml-3 mr-3">
|
|
|
|
|
<Link href="/" className="rounded-full">
|
|
|
|
|
<Image height={2000} width={2000} alt="Logo" className="border border-neutral-300 rounded-full" src="/logo.png" />
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
{navOptions.map((name) => (
|
|
|
|
|
<NavbarButton name={name} href={`/${name.toLowerCase()}`} key={name} />
|
|
|
|
|
))}
|
|
|
|
|
<NavbarButton name="About Us" href="/about" dropdownItems={aboutDropdown} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-grow" />
|
|
|
|
|
<button className="my-auto mr-4" onClick={() => setIsModalOpen(true)}>
|
|
|
|
|
<FaRegUserCircle size={22} />
|
|
|
|
|
</button>
|
|
|
|
|
<AuthModal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-03-10 13:27:47 +00:00
|
|
|
}
|