import { useNProgress } from "@tanem/react-nprogress"; import type { NextRouter } from "next/router"; import type { PropsWithChildren } from "react"; import { useEffect, useState, forwardRef } from "react"; import { classNames } from "@calcom/lib"; interface NProgressOptions { isAnimating: boolean; } export type NProgressProps = PropsWithChildren; const NProgress = forwardRef(({ isAnimating, ...rest }, ref) => { const { animationDuration, isFinished, progress } = useNProgress({ isAnimating, }); return (
); }); NProgress.displayName = "NProgress"; export const NProgressNextRouter = ({ router }: { router: NextRouter }) => { const [state, setState] = useState({ isRouteChanging: false, loadingKey: 0, }); useEffect(() => { const handleRouteChangeStart = () => { setState((prevState) => ({ ...prevState, isRouteChanging: true, loadingKey: prevState.loadingKey ^ 1, })); }; const handleRouteChangeEnd = () => { setState((prevState) => ({ ...prevState, isRouteChanging: false, })); }; router.events.on("routeChangeStart", handleRouteChangeStart); router.events.on("routeChangeComplete", handleRouteChangeEnd); router.events.on("routeChangeError", handleRouteChangeEnd); return () => { router.events.off("routeChangeStart", handleRouteChangeStart); router.events.off("routeChangeComplete", handleRouteChangeEnd); router.events.off("routeChangeError", handleRouteChangeEnd); }; }, [router.events]); const isAnimating = state.isRouteChanging; return ( <> ); };