import { ReactNode, useEffect, useState } from 'react'; import { useLocation } from 'react-router'; interface PageTransitionProps { children: ReactNode; } /** * Smooth page transition wrapper with modern loading indicator * Provides seamless transitions between pages without feeling like a page load * Uses subtle fade effects and minimal loading indicator */ export default function PageTransition({ children }: PageTransitionProps) { const location = useLocation(); const [isTransitioning, setIsTransitioning] = useState(false); const [displayChildren, setDisplayChildren] = useState(children); const [currentPath, setCurrentPath] = useState(location.pathname); useEffect(() => { // Only show transition if pathname actually changed if (location.pathname === currentPath) { setDisplayChildren(children); return; } // Start transition with minimal delay setIsTransitioning(true); setCurrentPath(location.pathname); // Quick fade-out, then swap content const fadeOutTimer = setTimeout(() => { setDisplayChildren(children); }, 100); // Complete transition quickly for smooth feel const fadeInTimer = setTimeout(() => { setIsTransitioning(false); }, 200); return () => { clearTimeout(fadeOutTimer); clearTimeout(fadeInTimer); }; }, [location.pathname, children, currentPath]); return (
{/* Subtle fade overlay - very light */}
{/* Minimal loading indicator - only shows briefly */} {isTransitioning && (
)} {/* Page content with smooth fade */}
{displayChildren}
); }