Skip to content

Commit

Permalink
Fix the dreaded stuttering load issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi committed Mar 27, 2024
1 parent 59a7034 commit 8ba9460
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/pages/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,41 @@ import {
const Landing: React.FC = () => {
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const handleLoad = () => {
setTimeout(() => {
setIsLoading(false);
}, 1000);
};
useEffect(() => {
const handleLoad = () => {
setTimeout(() => {
setIsLoading(false);
}, 1000); // Extra second after load event
};

window.addEventListener('load', handleLoad);
window.addEventListener('load', handleLoad);

return () => window.removeEventListener('load', handleLoad);
}, []);
if (document.readyState === 'complete') {
setTimeout(() => {
setIsLoading(false);
}, 1000);
}

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

return (
<div className="pt-[5rem] transition ease-in">
<Navbar />
<HeroStatSection />
<SponsorFAQSection />
<TeamSection />
<ContactSection />
<FooterSection />
<ScrollButton />
</div>
<>
{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>
</>
);
};

Expand Down

0 comments on commit 8ba9460

Please sign in to comment.