Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Make LoadingAnimation conditional #175

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions src/pages/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,42 @@ import {
ScrollButton,
LoadingAnimation,
} from '@components';
import { HeroAboutDesktop } from '@assets';

const Landing: React.FC = () => {
const [isLoading, setIsLoading] = useState(true);
const [componentLoaded, setComponentLoaded] = useState(false);
const [timerFinished, setTimerFinished] = useState(false);

useEffect(() => {
const handleLoad = () => {
setTimeout(() => {
setIsLoading(false);
}, 1000); // Extra second after load event
};
const desktopImage = new Image();
desktopImage.src = HeroAboutDesktop;
desktopImage.onload = () => setComponentLoaded(true);

window.addEventListener('load', handleLoad);
setTimeout(() => setTimerFinished(true), 2000);
}, []);

if (document.readyState === 'complete') {
setTimeout(() => {
setIsLoading(false);
}, 1000);
// Once the timer and component are finished -> display the page
useEffect(() => {
if (componentLoaded && timerFinished) {
setIsLoading(false);
}
}, [componentLoaded, timerFinished]);

return () => window.removeEventListener('load', handleLoad);
}, []);
if (isLoading) {
return <LoadingAnimation />;
}

return (
<>
{isLoading && (
<div className="loading-overlay">
<LoadingAnimation />
</div>
)}
<div className={`pt-[5rem] transition ease-in ${isLoading ? 'hidden' : 'block'}`}>
<Navbar />
<HeroStatSection />
<SponsorFAQSection />
<TeamSection />
<ContactSection />
<FooterSection />
<ScrollButton />
</div>
</>
<div className="pt-[5rem] transition ease-in">
<Navbar />
<HeroStatSection />
<SponsorFAQSection />
<TeamSection />
<ContactSection />
<FooterSection />
<ScrollButton />
</div>
);
};

Expand Down
Loading