import { useSearch } from "@/lib/context/isOpenState"; import { getCurrentSeason } from "@/utils/getTimes"; import { ArrowLeftIcon, ArrowUpCircleIcon } from "@heroicons/react/20/solid"; import { UserIcon } from "@heroicons/react/24/solid"; import { signIn, signOut, useSession } from "next-auth/react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; const getScrollPosition = (el = window) => ({ x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft, y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop, }); export function NewNavbar({ info, scrollP = 200, toTop = false, withNav = false, paddingY = "py-3", home = false, back = false, manga = false, shrink = false, }) { const { data: session } = useSession(); const router = useRouter(); const [scrollPosition, setScrollPosition] = useState(); const { setIsOpen } = useSearch(); const year = new Date().getFullYear(); const season = getCurrentSeason(); useEffect(() => { const handleScroll = () => { setScrollPosition(getScrollPosition()); }; // Add a scroll event listener when the component mounts window.addEventListener("scroll", handleScroll); // Clean up the event listener when the component unmounts return () => { window.removeEventListener("scroll", handleScroll); }; }, []); return ( <> = scrollP ? home ? "" : `bg-tersier shadow-tersier shadow-sm ${ shrink ? "py-1" : `${paddingY}` }` : `${paddingY}` } transition-all duration-200 ease-linear`} > {info ? ( <> { back ? router.back() : manga ? router.push("/en/search/manga") : router.push("/en"); }} > = scrollP + 80 ? "opacity-100" : "opacity-0" } transition-all duration-200 ease-linear`} > {info.title.romaji} > ) : ( // <>> moopa )} {withNav && ( This Season Manga Anime Schedule {!session && ( signIn("AniListProvider")} className="hover:text-action/80 transition-all duration-150 ease-linear" // className="px-2 py-1 ring-1 ring-action font-bold font-karla rounded-md" > Sign In )} {session && ( My List )} )} setIsOpen(true)} className="flex-center w-[26px] h-[26px]" > {/* */} {session ? ( router.push(`/en/profile/${session?.user.name}`) } className="rounded-full bg-white/30 overflow-hidden" > Profile signOut("AniListProvider")} className="hover:text-action" > Log out ) : ( signIn("AniListProvider")} title="Login With AniList" className="w-7 h-7 bg-white/30 rounded-full overflow-hidden shrink-0" > )} {/* */} {toTop && ( { window.scrollTo({ top: 0, behavior: "smooth", }); }} className={`${ scrollPosition?.y >= 180 ? "-translate-x-6 opacity-100" : "translate-x-[100%] opacity-0" } transform transition-all duration-300 ease-in-out fixed bottom-24 lg:bottom-14 right-0 z-[500]`} > )} > ); }