Create page transition wrapper component
cgen-f65b6f59c79a4af9a621096a3f7e4a19
This commit is contained in:
parent
1701845e29
commit
fc5e33e10d
1 changed files with 40 additions and 0 deletions
40
client/components/PageTransition.tsx
Normal file
40
client/components/PageTransition.tsx
Normal file
|
|
@ -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 && (
|
||||
<LoadingScreen
|
||||
message="Transitioning..."
|
||||
variant="overlay"
|
||||
size="md"
|
||||
/>
|
||||
)}
|
||||
<div className={`transition-all duration-500 ${isVisible ? 'animate-fade-in' : 'opacity-0'}`}>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue