diff --git a/web/src/components/Navbar.tsx b/web/src/components/Navbar.tsx index 9d8db1c..6346f00 100644 --- a/web/src/components/Navbar.tsx +++ b/web/src/components/Navbar.tsx @@ -9,6 +9,9 @@ import { ConnectButton } from "@rainbow-me/rainbowkit"; import { useAccount } from "wagmi"; import VouchMeLogo from "../image/VouchMeLogo.png"; +const NAVY_BG = "#0B1C2D"; +const SHEET_HEIGHT = "100vh"; + const Navbar = ({ toggleWalletConfig, useEnhancedConfig, @@ -16,167 +19,136 @@ const Navbar = ({ toggleWalletConfig: () => void; useEnhancedConfig: boolean; }) => { - const [isOpen, setIsOpen] = useState(false); - const [isScrolled, setIsScrolled] = useState(false); - const { address } = useAccount(); + const [open, setOpen] = useState(false); + const [scrolled, setScrolled] = useState(false); + const pathname = usePathname(); + const { address } = useAccount(); - const isAuthenticated = !!address; - const isLandingPage = pathname === "/"; + const isLanding = pathname === "/"; + const isAuth = !!address; + /* Navbar background on scroll */ useEffect(() => { - if (isLandingPage) { - const handleScroll = () => { - setIsScrolled(window.scrollY > 50); - }; - - window.addEventListener("scroll", handleScroll); - return () => window.removeEventListener("scroll", handleScroll); + if (!isLanding) { + setScrolled(true); + return; } - }, [isLandingPage]); - const scrollToSection = (sectionId: string) => { - const element = document.getElementById(sectionId); - if (element) { - element.scrollIntoView({ behavior: "smooth" }); - setIsOpen(false); - } + const onScroll = () => setScrolled(window.scrollY > 40); + window.addEventListener("scroll", onScroll); + onScroll(); + + return () => window.removeEventListener("scroll", onScroll); + }, [isLanding]); + + /* Lock body scroll */ + useEffect(() => { + document.body.style.overflow = open ? "hidden" : ""; + return () => { + document.body.style.overflow = ""; + }; + }, [open]); + + const scrollTo = (id: string) => { + document.getElementById(id)?.scrollIntoView({ behavior: "smooth" }); + setOpen(false); }; return ( - + )} + ); };