Skip to content

Commit a8b86b2

Browse files
authored
Merge pull request #46 from Kodiererin/Loader
Added a loader in the web-app.
2 parents 0370866 + 6f07df1 commit a8b86b2

File tree

5 files changed

+95
-27
lines changed

5 files changed

+95
-27
lines changed

Diff for: my-app/package-lock.json

+9-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: my-app/package.json

+2-1
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",

Diff for: my-app/src/App.jsx

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BrowserRouter, Routes, Route } from "react-router-dom";
2+
import { useState, useEffect } from "react";
23
import Home from "./pages/Home";
34
import About from "./pages/About";
45
import NotFound from "./pages/404";
@@ -7,32 +8,40 @@ import ContactForm from "./pages/Contact";
78
import Events from "./pages/Events";
89
import Base from "./layouts/Base";
910
import Subscribe from "./components/Subscribe";
10-
import { useState } from "react";
11-
// import NewsletterPage from "./pages/NewsletterPage";
11+
import Loader from "./components/Loader";
1212

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

2027
return (
2128
<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>
29+
{isVisible && <Subscribe handle={handleSetVisible} />}
30+
<Loader loading={loading} />
31+
{!loading && (
32+
<BrowserRouter>
33+
<Base>
34+
<Routes>
35+
<Route path="/" element={<Home handle={handleSetVisible} />} />
36+
<Route path="/about-us" element={<About handle={handleSetVisible} />} />
37+
<Route path="/community" element={<Community />} />
38+
<Route path="/events" element={<Events />} />
39+
<Route path="/contact-us" element={<ContactForm />} />
40+
<Route path="*" element={<NotFound />} />
41+
</Routes>
42+
</Base>
43+
</BrowserRouter>
44+
)}
3645
</div>
3746
);
3847
}

Diff for: my-app/src/assets/images/codex-logo.png

6.58 KB
Loading

Diff for: my-app/src/components/Loader.jsx

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { useEffect, useState } from "react";
2+
import { motion, AnimatePresence } from "framer-motion";
3+
import logo from "../assets/images/codex-logo.png";
4+
5+
const Loader = ({ loading }) => {
6+
const [showExplore, setShowExplore] = useState(false);
7+
8+
useEffect(() => {
9+
const timer = setTimeout(() => {
10+
setShowExplore(true);
11+
}, 500);
12+
13+
return () => clearTimeout(timer);
14+
}, []);
15+
16+
return (
17+
<AnimatePresence>
18+
{loading && (
19+
<motion.div
20+
className="flex items-center justify-center h-screen bg-primary"
21+
initial={{ opacity: 1, y: 0 }}
22+
exit={{ opacity: 0, y: -100 }} // Exit animation: fades and slides up
23+
transition={{ duration: 0.5 }}
24+
>
25+
<div className="flex flex-col items-center">
26+
<img src={logo} alt="Logo" className="w-25" />
27+
28+
<div className="relative text-white text-1xl mt-0.5">
29+
<motion.div
30+
className="relative"
31+
initial={{ opacity: 1, y: 0 }}
32+
animate={{ opacity: showExplore ? 0 : 1, y: showExplore ? -20 : 0 }}
33+
transition={{ duration: 0.25 }}
34+
>
35+
We <span className="text-secondary">Code</span>
36+
</motion.div>
37+
38+
<motion.div
39+
className="relative"
40+
initial={{ opacity: 0, y: 20 }}
41+
animate={{ opacity: showExplore ? 1 : 0, y: showExplore ? -20 : 0 }}
42+
transition={{ duration: 0.25 }}
43+
>
44+
We <span className="text-secondary">Explore</span>
45+
</motion.div>
46+
</div>
47+
</div>
48+
</motion.div>
49+
)}
50+
</AnimatePresence>
51+
);
52+
};
53+
54+
export default Loader;

0 commit comments

Comments
 (0)