Skip to content

Commit d696f0d

Browse files
Merge pull request #65 from codeXsit/codex-baffle-loader
feat: added loader
2 parents c2b4946 + 55c23d2 commit d696f0d

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@fontsource/league-gothic": "^5.0.18",
1919
"@fontsource/poppins": "^5.0.8",
2020
"@vitejs/plugin-react": "^4.2.1",
21+
"baffle": "^0.3.6",
2122
"framer-motion": "^11.5.4",
2223
"lodash": "^4.17.21",
2324
"prop-types": "^15.8.1",

src/App.jsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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";
45
import routes from "@/routes/index";
56
import Navbar from "@/components/Navbar/index";
67
import Cursor from "./components/Cursor";
78
import CursorVariantProvider from "@/context/CursorVariantProvider";
9+
import Loader from "@/components/Loader";
810

911
const navLinks = [
1012
{ name: "About Us", path: "/about-us" },
@@ -15,24 +17,34 @@ const navLinks = [
1517
];
1618

1719
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+
1827
return (
1928
<CursorVariantProvider>
2029
<AnimatePresence>
21-
<Router>
22-
<Navbar links={navLinks} />
23-
<Cursor />
24-
25-
<ToastContainer />
26-
<Routes>
27-
{routes.map((route) => (
28-
<Route
29-
path={route.path}
30-
element={route.render}
31-
key={route.label}
32-
/>
33-
))}
34-
</Routes>
35-
</Router>
30+
{loading ? (
31+
<Loader onLoadComplete={handleLoadComplete} />
32+
) : (
33+
<Router>
34+
<Navbar links={navLinks} />
35+
<Cursor />
36+
<ToastContainer />
37+
<Routes>
38+
{routes.map((route) => (
39+
<Route
40+
path={route.path}
41+
element={route.render}
42+
key={route.label}
43+
/>
44+
))}
45+
</Routes>
46+
</Router>
47+
)}
3648
</AnimatePresence>
3749
</CursorVariantProvider>
3850
);

src/components/Loader/index.jsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import baffle from "baffle";
2+
import PropTypes from "prop-types";
3+
import { useEffect } from "react";
4+
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);
15+
16+
const timer = setTimeout(() => {
17+
onLoadComplete();
18+
}, 3500);
19+
20+
return () => clearTimeout(timer);
21+
}, [onLoadComplete]);
22+
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+
);
30+
}
31+
32+
Loader.propTypes = {
33+
onLoadComplete: PropTypes.func.isRequired,
34+
};
35+
36+
export default Loader;

src/routes/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import About from "@/pages/About/index";
44
import Gallery from "@/pages/Gallery/Gallery";
55
import Contact from "@/pages/Contact";
66
import PageNotFound from "../pages/PageNotFound";
7+
import Loader from "@/components/Loader";
78

89
const routes = [
10+
{
11+
label: "Loader",
12+
path: "/loader",
13+
requireAuth: false,
14+
render: <Loader />,
15+
},
916
{
1017
label: "Contact",
1118
path: "/contact",

0 commit comments

Comments
 (0)