diff --git a/client/components/PageTransition.tsx b/client/components/PageTransition.tsx new file mode 100644 index 00000000..39010642 --- /dev/null +++ b/client/components/PageTransition.tsx @@ -0,0 +1,40 @@ +import { useEffect, useState } from "react"; +import { useLocation } from "react-router-dom"; +import LoadingScreen from "./LoadingScreen"; + +interface PageTransitionProps { + children: React.ReactNode; +} + +export default function PageTransition({ children }: PageTransitionProps) { + const [isLoading, setIsLoading] = useState(false); + const [isVisible, setIsVisible] = useState(true); + const location = useLocation(); + + useEffect(() => { + setIsLoading(true); + setIsVisible(false); + + const timer = setTimeout(() => { + setIsLoading(false); + setIsVisible(true); + }, 600); + + return () => clearTimeout(timer); + }, [location.pathname]); + + return ( + <> + {isLoading && ( + + )} +
+ {children} +
+ + ); +}