Skip to content

Commit 1024b00

Browse files
committed
(Feature) : Added a Loader
1 parent b0931ad commit 1024b00

File tree

5 files changed

+89
-32
lines changed

5 files changed

+89
-32
lines changed

my-app/package-lock.json

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

my-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"@headlessui/react": "^2.1.8",
1414
"@wojtekmaj/react-hooks": "^1.21.0",
15-
"framer-motion": "^11.5.6",
15+
"framer-motion": "^11.11.7",
16+
"my-app": "file:",
1617
"react": "^18.3.1",
1718
"react-dom": "^18.3.1",
1819
"react-helmet": "^6.1.0",

my-app/src/App.jsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// src/App.jsx
2+
13
import { BrowserRouter, Routes, Route } from "react-router-dom";
4+
import { useState, useEffect } from "react";
25
import Home from "./pages/Home";
36
import About from "./pages/About";
47
import NotFound from "./pages/404";
@@ -7,32 +10,41 @@ import ContactForm from "./pages/Contact";
710
import Events from "./pages/Events";
811
import Base from "./layouts/Base";
912
import Subscribe from "./components/Subscribe";
10-
import { useState } from "react";
11-
// import NewsletterPage from "./pages/NewsletterPage";
13+
import Loader from "./components/Loader";
1214

1315
export default function App() {
14-
const [isVisible, setIsVisible] = useState(false);
15-
16-
const handleSetVisible = (value)=>{
17-
setIsVisible(value);
18-
};
16+
const [isVisible, setIsVisible] = useState(false);
17+
const [loading, setLoading] = useState(true);
18+
19+
useEffect(() => {
20+
const timer = setTimeout(() => {
21+
setLoading(false);
22+
}, 1500); // I have Adjusted loader time to 1.5 seconds for smoother transition
23+
24+
return () => clearTimeout(timer); // Cleaning up timer
25+
}, []);
26+
27+
const handleSetVisible = (value) => setIsVisible(value);
1928

2029
return (
2130
<div className="bg-primary">
22-
{isVisible&&<Subscribe handle={handleSetVisible} />}
23-
<BrowserRouter>
24-
<Base>
25-
<Routes>
26-
<Route path="/" element={<Home handle={handleSetVisible} />} />
27-
<Route path="/about-us" element={<About handle={handleSetVisible} />} />
28-
<Route path="/community" element={<Community />} />
29-
<Route path="/events" element={<Events />} />
30-
<Route path="/contact-us" element={<ContactForm />} />
31-
{/* <Route path="/newsletter" element={<NewsletterPage />} /> */}
32-
<Route path="*" element={<NotFound />} />
33-
</Routes>
34-
</Base>
35-
</BrowserRouter>
31+
{isVisible && <Subscribe handle={handleSetVisible} />}
32+
{loading ? (
33+
<Loader />
34+
) : (
35+
<BrowserRouter>
36+
<Base>
37+
<Routes>
38+
<Route path="/" element={<Home handle={handleSetVisible} />} />
39+
<Route path="/about-us" element={<About handle={handleSetVisible} />} />
40+
<Route path="/community" element={<Community />} />
41+
<Route path="/events" element={<Events />} />
42+
<Route path="/contact-us" element={<ContactForm />} />
43+
<Route path="*" element={<NotFound />} />
44+
</Routes>
45+
</Base>
46+
</BrowserRouter>
47+
)}
3648
</div>
3749
);
3850
}
6.58 KB
Loading

my-app/src/components/Loader.jsx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1-
import React from 'react'
1+
// src/components/Loader.jsx
2+
3+
import React, { useEffect, useState } from "react";
4+
import { motion } from "framer-motion";
5+
import logo from "../assets/images/codex-logo.png";
6+
7+
const Loader = () => {
8+
const [showExplore, setShowExplore] = useState(false);
9+
10+
useEffect(() => {
11+
const timer = setTimeout(() => {
12+
setShowExplore(true);
13+
}, 500);
14+
15+
return () => clearTimeout(timer);
16+
}, []);
217

3-
export default function Loader() {
418
return (
5-
<div>Loader</div>
6-
)
7-
}
19+
<div className="flex items-center justify-center h-screen bg-primary">
20+
<div className="flex flex-col items-center">
21+
<img src={logo} alt="Logo" className="w-25" />
22+
23+
<div className="relative text-white text-1xl mt-0.5">
24+
<motion.div
25+
className="relative"
26+
initial={{ opacity: 1, y: 0 }}
27+
animate={{ opacity: showExplore ? 0 : 1, y: showExplore ? -20 : 0 }}
28+
transition={{ duration: 0.25 }}
29+
>
30+
We <span className="text-secondary">Code</span>
31+
</motion.div>
32+
33+
<motion.div
34+
className="relative"
35+
initial={{ opacity: 0, y: 20 }}
36+
animate={{ opacity: showExplore ? 1 : 0, y: showExplore ? 0 : 20 }}
37+
transition={{ duration: 0.25 }}
38+
>
39+
We <span className="text-secondary">Explore</span>
40+
</motion.div>
41+
</div>
42+
</div>
43+
</div>
44+
);
45+
};
46+
47+
export default Loader;

0 commit comments

Comments
 (0)