Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 19x 19x 19x 19x | import { MutableRefObject, useEffect } from "react"; import { useRouter } from "next/router"; import { useModal, useSpotify } from "hooks"; import { DisplayInFullScreen } from "types/spotify"; export function useRouterEvents( onAppScroll: () => void, appRef?: MutableRefObject<HTMLDivElement | undefined> ): void { const router = useRouter(); const { setDisplayInFullScreen } = useSpotify(); const { setModalData } = useModal(); useEffect(() => { const app = appRef?.current ?? document.querySelector("#right .simplebar-content-wrapper"); const handleRouteChange = () => { app?.scrollTo(0, 0); setDisplayInFullScreen(DisplayInFullScreen.App); setModalData(null); }; router.events.on("routeChangeComplete", handleRouteChange); app?.addEventListener("scroll", onAppScroll); return () => { router.events.off("routeChangeComplete", handleRouteChange); app?.removeEventListener("scroll", onAppScroll); }; }, [router, appRef, onAppScroll, setDisplayInFullScreen, setModalData]); } |