Skip to content

Commit 55c23d2

Browse files
fix: content glitch over preloader
co-authored-by: Miran Firdausi [email protected]
1 parent 283a9a6 commit 55c23d2

File tree

4 files changed

+47
-44
lines changed

4 files changed

+47
-44
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ dist-ssr
2525

2626
# package resolution config
2727
package-lock.json
28-
yarn.lock
28+
yarn.lock
29+
30+
.env

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@fontsource/poppins": "^5.0.8",
2020
"@vitejs/plugin-react": "^4.2.1",
2121
"baffle": "^0.3.6",
22-
"baffle-react": "^0.0.2",
2322
"framer-motion": "^11.5.4",
2423
"lodash": "^4.17.21",
2524
"prop-types": "^15.8.1",

src/App.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from "react";
12
import { AnimatePresence } from "framer-motion";
23
import { HashRouter as Router, Routes, Route } from "react-router-dom";
34
import { ToastContainer } from "react-toastify";
@@ -16,14 +17,23 @@ const navLinks = [
1617
];
1718

1819
function App() {
20+
const [loading, setLoading] = useState(true);
21+
22+
// Function to be called when the loader finishes
23+
const handleLoadComplete = () => {
24+
setLoading(false); // Set loading to false once the loader is done
25+
};
26+
1927
return (
2028
<CursorVariantProvider>
21-
<Loader />
2229
<AnimatePresence>
30+
{loading ? (
31+
<Loader onLoadComplete={handleLoadComplete} />
32+
) : (
2333
<Router>
24-
<Navbar links={navLinks} />
25-
<Cursor />
26-
<ToastContainer />
34+
<Navbar links={navLinks} />
35+
<Cursor />
36+
<ToastContainer />
2737
<Routes>
2838
{routes.map((route) => (
2939
<Route
@@ -34,6 +44,7 @@ function App() {
3444
))}
3545
</Routes>
3646
</Router>
47+
)}
3748
</AnimatePresence>
3849
</CursorVariantProvider>
3950
);

src/components/Loader/index.jsx

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,36 @@
11
import baffle from "baffle";
2-
import { useEffect, useState } from "react";
2+
import PropTypes from "prop-types";
3+
import { useEffect } from "react";
34

4-
function Loader() {
5-
const [isVisible, setIsVisible] = useState(true);
6-
const [isDisplayed, setIsDisplayed] = useState(true);
5+
function Loader({ onLoadComplete }) {
6+
useEffect(() => {
7+
const target = baffle(".loader");
8+
target.set({
9+
characters: "█▓█ ▒░/▒░ █░▒▓/ █▒▒ ▓▒▓/█<░▒ ▓/░>",
10+
speed: 120,
11+
reveal: 0,
12+
});
13+
target.start();
14+
target.reveal(3000, 0);
715

8-
useEffect(() => {
9-
const target = baffle('.loader');
10-
target.set({
11-
characters: "█▓█ ▒░/▒░ █░▒▓/ █▒▒ ▓▒▓/█<░▒ ▓/░>",
12-
speed: 120
13-
});
14-
target.start();
15-
target.reveal(3000, 100);
16+
const timer = setTimeout(() => {
17+
onLoadComplete();
18+
}, 3500);
1619

17-
const timer = setTimeout(() => {
18-
setIsVisible(false);
19-
setTimeout(() => {
20-
setIsDisplayed(false);
21-
}, 1000);
22-
}, 5000);
20+
return () => clearTimeout(timer);
21+
}, [onLoadComplete]);
2322

24-
return () => clearTimeout(timer);
25-
}, []);
26-
27-
if (!isDisplayed) {
28-
return null;
29-
}
30-
31-
return (
32-
<div
33-
className={`absolute top-0 left-0 w-full h-full flex justify-center items-center bg-secondary-dark bg-opacity-100 transition-opacity duration-1000 ${
34-
isVisible ? 'opacity-100' : 'opacity-0'
35-
}`}
36-
style={{ display: isDisplayed ? 'flex' : 'none' }}
37-
>
38-
<div className="loader text-secondary-light font-poppins text-4xl sm:text-5xl md:text-6xl lg:text-7xl xl:text-8xl">
39-
Welcome to CodeX
40-
</div>
41-
</div>
42-
);
23+
return (
24+
<div className="absolute top-0 left-0 w-full h-full flex justify-center items-center bg-secondary-dark bg-opacity-100 transition-opacity duration-1000">
25+
<div className="loader text-secondary-light font-medium font-poppins text-3xl sm:text-4xl md:text-5xl xl:text-6xl">
26+
Welcome to CodeX
27+
</div>
28+
</div>
29+
);
4330
}
4431

45-
export default Loader;
32+
Loader.propTypes = {
33+
onLoadComplete: PropTypes.func.isRequired,
34+
};
35+
36+
export default Loader;

0 commit comments

Comments
 (0)