import { useApolloClient } from "@apollo/client"; import { BellIcon as BellOutline, BookmarkIcon as BookmarkOutline, GlobeAltIcon as GlobeOutline, HomeIcon as HomeOutline, UserCircleIcon, UserGroupIcon as UserGroupOutline } from "@heroicons/react/24/outline"; import { BellIcon as BellSolid, BookmarkIcon as BookmarkSolid, GlobeAltIcon as GlobeSolid, HomeIcon as HomeSolid, UserGroupIcon as UserGroupSolid } from "@heroicons/react/24/solid"; import { STATIC_IMAGES_URL } from "@hey/data/constants"; import { GroupsDocument, NotificationIndicatorDocument, NotificationsDocument, PostBookmarksDocument, PostsExploreDocument, PostsForYouDocument, TimelineDocument, TimelineHighlightsDocument } from "@hey/indexer"; import { type MouseEvent, memo, type ReactNode, useCallback, useState } from "react"; import { Link, useLocation } from "react-router"; import Pro from "@/components/Shared/Navbar/NavItems/Pro"; import { Image, Spinner, Tooltip } from "@/components/Shared/UI"; import useHasNewNotifications from "@/hooks/useHasNewNotifications"; import { useAuthModalStore } from "@/store/non-persisted/modal/useAuthModalStore"; import { useAccountStore } from "@/store/persisted/useAccountStore"; import SignedAccount from "./SignedAccount"; const navigationItems = { "/": { outline: , refreshDocs: [ TimelineDocument, TimelineHighlightsDocument, PostsForYouDocument ], solid: , title: "Home" }, "/bookmarks": { outline: , refreshDocs: [PostBookmarksDocument], solid: , title: "Bookmarks" }, "/explore": { outline: , refreshDocs: [PostsExploreDocument], solid: , title: "Explore" }, "/groups": { outline: , refreshDocs: [GroupsDocument], solid: , title: "Groups" }, "/notifications": { outline: , refreshDocs: [NotificationsDocument, NotificationIndicatorDocument], solid: , title: "Notifications" } }; interface NavItemProps { url: string; icon: ReactNode; onClick?: (e: MouseEvent) => void; } const NavItem = memo(({ icon, onClick, url }: NavItemProps) => ( {icon} )); const NavItems = memo(({ isLoggedIn }: { isLoggedIn: boolean }) => { const { pathname } = useLocation(); const hasNewNotifications = useHasNewNotifications(); const client = useApolloClient(); const [refreshingRoute, setRefreshingRoute] = useState(null); const routes = [ "/", "/explore", ...(isLoggedIn ? ["/notifications", "/groups", "/bookmarks"] : []) ]; return ( <> {routes.map((route) => { let icon = pathname === route ? navigationItems[route as keyof typeof navigationItems].solid : navigationItems[route as keyof typeof navigationItems].outline; if (refreshingRoute === route) { icon = ; } const iconWithIndicator = route === "/notifications" ? ( {icon} {hasNewNotifications && ( )} ) : ( icon ); const handleClick = async (e: MouseEvent) => { const item = navigationItems[route as keyof typeof navigationItems]; const isSameRoute = pathname === route; if (!isSameRoute || !("refreshDocs" in item) || !item.refreshDocs) { return; } e.preventDefault(); window.scrollTo(0, 0); setRefreshingRoute(route); try { await client.refetchQueries({ include: item.refreshDocs }); } finally { setRefreshingRoute(null); } }; return ( ); })} ); }); const Navbar = () => { const { pathname } = useLocation(); const { currentAccount } = useAccountStore(); const { setShowAuthModal } = useAuthModalStore(); const handleLogoClick = useCallback( (e: MouseEvent) => { if (pathname === "/") { e.preventDefault(); window.scrollTo(0, 0); } }, [pathname] ); const handleAuthClick = useCallback(() => { setShowAuthModal(true); }, []); return ( ); }; export default memo(Navbar);