From b5c1e47a63f811c795d21b308aa09fee620d7548 Mon Sep 17 00:00:00 2001 From: Kris Baumgartner Date: Tue, 16 Jul 2024 21:20:13 -0700 Subject: [PATCH] Fix home overlay --- app/Canvas.tsx | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/Canvas.tsx b/app/Canvas.tsx index 606835908..df660dc85 100644 --- a/app/Canvas.tsx +++ b/app/Canvas.tsx @@ -21,28 +21,48 @@ export default function PmndrsCanvas() { const onPause = useCanvasApi((state) => state.onPause) const onPlay = useCanvasApi((state) => state.onPlay) const isLoaded = useCanvasApi((state) => state.isLoaded) + const prevIsLoaded = useRef(isLoaded) const pathname = usePathname() - const isHome = useRef(pathname === '/') - isHome.current = pathname === '/' + const isHome = pathname === '/' + const isHomeRef = useRef(isHome) + isHomeRef.current = isHome const [showOverlay, setShowOverlay] = useState(false) useEffect(() => { let timeout: NodeJS.Timeout - if (isHome.current) { - timeout = setTimeout(() => { + // if (isHome.current) { + // timeout = setTimeout(() => { + // setShowOverlay(true) + // }, 1000) + // } else { + // setShowOverlay(false) + // } + + if (isHome) { + if (!prevIsLoaded.current && !isLoaded) return + + if (!prevIsLoaded.current && isLoaded) { + timeout = setTimeout(() => { + setShowOverlay(true) + }, 1000) + } + + if (prevIsLoaded.current && isLoaded) { setShowOverlay(true) - }, 1000) + } } else { setShowOverlay(false) } + prevIsLoaded.current = isLoaded + return () => { clearTimeout(timeout) } - }, [isLoaded]) + }, [isLoaded, isHome]) const [props, springApi] = useSpring(() => ({ opacity: 0, @@ -78,7 +98,7 @@ export default function PmndrsCanvas() { useEffect(() => { if (!isLoaded) return - if (!isHome.current) return + if (!isHomeRef.current) return springApi.start({ opacity: 1,