From 59f4dbc3ed71299ec97a37325e9454f48e98f272 Mon Sep 17 00:00:00 2001 From: Noah Kim Date: Wed, 11 Dec 2024 23:45:50 -0800 Subject: [PATCH 1/2] Change onLoad property to update useRef object rather than state --- .../(home)/sections/Landing/Landing.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx b/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx index fdc0b74b..7637f0ef 100644 --- a/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx +++ b/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx @@ -23,9 +23,19 @@ import styles from "./Landing.module.css"; const Landing = () => { const deadlinePassed = hasDeadlinePassed(); const applicationsOpened = haveApplicationsOpened(); - const [loaded, setLoaded] = useState(0); + const [imagesLoaded, setImagesLoaded] = useState(false); const scrollTo = useRef(null); + const totalImages = 8; // Total number of images + const loadCount = useRef(0); + + const handleImageLoad = () => { + loadCount.current += 1; + if (loadCount.current === totalImages) { + setImagesLoaded(true); + } + }; + const applyClick = () => { scrollTo.current?.scrollIntoView({ behavior: "smooth" }); }; @@ -36,7 +46,7 @@ const Landing = () => { className={`${ styles.landingBackground } min-h-screen pb-[200px] relative overflow-hidden max-lg:h-[1500px] ${ - loaded < 8 ? "blur-sm" : "" + imagesLoaded ? "" : "blur-sm" } duration-500`} >
{ clouds setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} />
@@ -94,7 +103,7 @@ const Landing = () => { priority alt="background pillars" className="absolute min-w-[570px] w-full 2xl:max-h-[2500px]" - onLoad={() => setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} />
@@ -115,7 +124,7 @@ const Landing = () => { priority alt="background pillars" className="w-full" - onLoad={() => setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} />
@@ -129,7 +138,7 @@ const Landing = () => { priority alt="castle" className="w-full 2xl:w-[75vw] h-full mt-[50px] sm:mt-[100px] min-w-[520px]" - onLoad={() => setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} /> @@ -138,21 +147,21 @@ const Landing = () => { priority alt="anteater cliff" className={`absolute top-[31%] max-lg:top-[33%] min-w-[520px] w-full`} - onLoad={() => setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} /> clouds setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} /> clouds setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} /> { priority alt="foreground clouds" className={`${styles.bottomCloud} absolute bottom-[200px] md:bottom-16 xxl:bottom-0 w-full`} - onLoad={() => setLoaded((loaded) => loaded + 1)} + onLoad={handleImageLoad} /> From 5393bfe01dd958b9f3ff52e82b29806d4ef81930 Mon Sep 17 00:00:00 2001 From: Noah Kim Date: Thu, 12 Dec 2024 00:35:00 -0800 Subject: [PATCH 2/2] Make images load at same time and add loading animation --- .../(home)/sections/Landing/Landing.tsx | 239 ++++++++++-------- 1 file changed, 136 insertions(+), 103 deletions(-) diff --git a/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx b/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx index 7637f0ef..ca50a0b3 100644 --- a/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx +++ b/apps/site/src/app/(main)/(home)/sections/Landing/Landing.tsx @@ -1,6 +1,6 @@ "use client"; -import { Suspense, useRef, useState } from "react"; +import { Suspense, useRef, useState, useEffect } from "react"; import { PerspectiveCamera } from "@react-three/drei"; import { motion } from "framer-motion"; import Image from "next/image"; @@ -26,153 +26,186 @@ const Landing = () => { const [imagesLoaded, setImagesLoaded] = useState(false); const scrollTo = useRef(null); - const totalImages = 8; // Total number of images + const totalImages = 8; const loadCount = useRef(0); - + + const [dots, setDots] = useState(0); + const handleImageLoad = () => { loadCount.current += 1; - if (loadCount.current === totalImages) { + if (loadCount.current === totalImages) { setImagesLoaded(true); - } + } }; const applyClick = () => { scrollTo.current?.scrollIntoView({ behavior: "smooth" }); }; + useEffect(() => { + let interval: NodeJS.Timeout | null = null; + + if (!imagesLoaded) { + interval = setInterval(() => { + setDots((prevDots) => (prevDots < 8 ? prevDots + 1 : 8)); + }, 50); + } + + return () => { + if (interval) clearInterval(interval); + }; + }, [imagesLoaded]); + return ( <>
+

Loading...

+

+ {"■".repeat(dots)} + {"□".repeat(8 - dots)} +

+
+
- - - - -
-
-
-

- January 24-26, 2025 -

-

- IrvineHacks -

-
+ + + + + +
+
+
+

+ January 24-26, 2025 +

+

+ IrvineHacks +

+
- {deadlinePassed ? ( -
+ ) : ( +
+
+ clouds - ) : applicationsOpened ? ( -
-
-
- clouds -
background pillars -
- background castle +
+ + background pillars + +
-
background pillars -
- castle - - - anteater cliff - clouds + clouds + clouds +
clouds
- foreground clouds +
-