"use client"; import { useRef, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { useMount, useUnmount } from "react-use"; import classNames from "classnames"; import { Button } from "@/components/ui/button"; import Logo from "@/assets/logo.svg"; import { useUser } from "@/hooks/useUser"; import { UserMenu } from "@/components/user-menu"; const navigationLinks = [ { name: "Create Website", href: "/projects/new", }, { name: "Features", href: "#features", }, { name: "Community", href: "#community", }, { name: "Deploy", href: "#deploy", }, ]; export default function Navigation() { const { openLoginWindow, user } = useUser(); const [hash, setHash] = useState(""); const selectorRef = useRef(null); const linksRef = useRef( new Array(navigationLinks.length).fill(null) ); const [isScrolled, setIsScrolled] = useState(false); useMount(() => { const handleScroll = () => { const scrollTop = window.scrollY; setIsScrolled(scrollTop > 100); }; const initialHash = window.location.hash; if (initialHash) { setHash(initialHash); calculateSelectorPosition(initialHash); } window.addEventListener("scroll", handleScroll); }); useUnmount(() => { window.removeEventListener("scroll", () => {}); }); const handleClick = (href: string) => { setHash(href); calculateSelectorPosition(href); }; const calculateSelectorPosition = (href: string) => { if (selectorRef.current && linksRef.current) { const index = navigationLinks.findIndex((l) => l.href === href); const targetLink = linksRef.current[index]; if (targetLink) { const targetRect = targetLink.getBoundingClientRect(); selectorRef.current.style.left = targetRect.left + "px"; selectorRef.current.style.width = targetRect.width + "px"; } } }; return (
); }