diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index bada69d..1350193 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,173 +1,15 @@ -import { NavLink, Link } from "react-router-dom"; -import { useEffect, useMemo, useRef, useState, useContext } from "react"; +import { NavLink, Link, useNavigate, useLocation } from "react-router-dom"; +import { useState, useContext } from "react"; import { ThemeContext } from "../context/ThemeContext"; -import { Moon, Sun, Menu, X, ChevronDown, BadgeInfo, LogOut, User } from "lucide-react"; - -type NavbarUser = { - id?: string; - username?: string; - email?: string; -}; - -const AUTH_STORAGE_KEY = "github_tracker_auth_user"; - -const readStoredUser = (): NavbarUser | null => { - if (typeof window === "undefined") { - return null; - } - - const storedUser = window.localStorage.getItem(AUTH_STORAGE_KEY); - - if (!storedUser) { - return null; - } - - try { - const parsedUser = JSON.parse(storedUser) as NavbarUser; - return parsedUser?.username ? parsedUser : null; - } catch { - return null; - } -}; - -type ProfileDropdownProps = { - user: NavbarUser; - onLogout: () => void; - onCloseMenu?: () => void; - mobile?: boolean; -}; - -const ProfileDropdown: React.FC = ({ user, onLogout, onCloseMenu, mobile = false }) => { - const [isOpen, setIsOpen] = useState(false); - const profileMenuRef = useRef(null); - const displayName = useMemo(() => user.username ?? "Profile", [user.username]); - - useEffect(() => { - const handleOutsideClick = (event: MouseEvent) => { - if (profileMenuRef.current && !profileMenuRef.current.contains(event.target as Node)) { - setIsOpen(false); - } - }; - - document.addEventListener("mousedown", handleOutsideClick); - return () => document.removeEventListener("mousedown", handleOutsideClick); - }, []); - - const closeMenu = () => setIsOpen(false); - - if (mobile) { - return ( -
-
-
- {displayName.charAt(0).toUpperCase()} -
-
-

{displayName}

-

{user.email ?? "Signed in"}

-
-
- -
- - - View Profile - - - - Account Details - - -
-
- ); - } - - return ( -
- - - {isOpen && ( -
-
-

Account

-
-
- {displayName.charAt(0).toUpperCase()} -
-
-

{displayName}

-

{user.email ?? "No email available"}

-
-
-
- -
- - - View Profile - - - - Account Details - - -
-
- )} -
- ); -}; +import { Moon, Sun, Menu, X } from "lucide-react"; const Navbar: React.FC = () => { const [isOpen, setIsOpen] = useState(false); const [user, setUser] = useState(() => readStoredUser()); const themeContext = useContext(ThemeContext); - const authContext = useContext(AuthContext); const navigate = useNavigate(); + const location = useLocation(); if (!themeContext || !authContext) return null; @@ -181,6 +23,9 @@ const Navbar: React.FC = () => { : "text-slate-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 hover:bg-gray-50 dark:hover:bg-gray-800" }`; + const featureLinkStyles = + "px-4 py-2 rounded-xl text-sm lg:text-base font-semibold transition-all duration-300 text-slate-700 dark:text-gray-300 hover:text-blue-500 cursor-pointer"; + const closeMenu = () => setIsOpen(false); const handleLogout = () => { if (typeof window !== "undefined") { @@ -201,6 +46,23 @@ const Navbar: React.FC = () => { } }; + // Smooth scroll to #features on homepage + const handleFeaturesClick = () => { + closeMenu(); + if (location.pathname === "/") { + const section = document.getElementById("features"); + if (section) { + section.scrollIntoView({ behavior: "smooth" }); + } + } else { + navigate("/#features"); + setTimeout(() => { + const section = document.getElementById("features"); + if (section) section.scrollIntoView({ behavior: "smooth" }); + }, 100); + } + }; + return (