Skip to content

Commit 1c94c4e

Browse files
authored
Merge pull request #49 from Kodiererin/Loader
(Feature) : Added the Unblur effect
2 parents a8b86b2 + aa7a553 commit 1c94c4e

File tree

2 files changed

+61
-60
lines changed

2 files changed

+61
-60
lines changed

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

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BrowserRouter, Routes, Route } from "react-router-dom";
22
import { useState, useEffect } from "react";
3+
import { motion } from "framer-motion";
34
import Home from "./pages/Home";
45
import About from "./pages/About";
56
import NotFound from "./pages/404";
@@ -10,37 +11,44 @@ import Base from "./layouts/Base";
1011
import Subscribe from "./components/Subscribe";
1112
import Loader from "./components/Loader";
1213

13-
export default function App() {
14-
const [isVisible, setIsVisible] = useState(false);
14+
// Custom hook to handle the loader
15+
const useLoader = (duration = 1500) => {
1516
const [loading, setLoading] = useState(true);
16-
1717
useEffect(() => {
18-
const timer = setTimeout(() => {
19-
setLoading(false);
20-
}, 1500); // Adjusted loader time to 1.5 seconds for smoother transition
18+
const timer = setTimeout(() => setLoading(false), duration);
19+
return () => clearTimeout(timer); // This is the cleanup timer
20+
}, [duration]);
21+
return loading;
22+
};
2123

22-
return () => clearTimeout(timer); // Cleaning up timer
23-
}, []);
24-
25-
const handleSetVisible = (value) => setIsVisible(value);
24+
export default function App() {
25+
const [isVisible, setVisible] = useState(false);
26+
const loading = useLoader(); // Loader logic
2627

2728
return (
2829
<div className="bg-primary">
29-
{isVisible && <Subscribe handle={handleSetVisible} />}
30-
<Loader loading={loading} />
30+
{isVisible && <Subscribe handle={setVisible} />}
31+
{loading && <Loader loading={loading} />}
3132
{!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>
33+
<motion.div
34+
initial={{ filter: "blur(10px)" }}
35+
animate={{ filter: "blur(0px)" }}
36+
transition={{ duration: 0.5 }}
37+
className="transition-all duration-400"
38+
>
39+
<BrowserRouter>
40+
<Base>
41+
<Routes>
42+
<Route path="/" element={<Home handle={setVisible} />} />
43+
<Route path="/about-us" element={<About handle={setVisible} />} />
44+
<Route path="/community" element={<Community />} />
45+
<Route path="/events" element={<Events />} />
46+
<Route path="/contact-us" element={<ContactForm />} />
47+
<Route path="*" element={<NotFound />} />
48+
</Routes>
49+
</Base>
50+
</BrowserRouter>
51+
</motion.div>
4452
)}
4553
</div>
4654
);

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

+29-36
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// src/components/Loader.jsx
2+
13
import React, { useEffect, useState } from "react";
2-
import { motion, AnimatePresence } from "framer-motion";
4+
import { motion } from "framer-motion";
35
import logo from "../assets/images/codex-logo.png";
46

5-
const Loader = ({ loading }) => {
7+
const Loader = () => {
68
const [showExplore, setShowExplore] = useState(false);
79

810
useEffect(() => {
@@ -14,40 +16,31 @@ const Loader = ({ loading }) => {
1416
}, []);
1517

1618
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>
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 ? -20 : 0 }}
37+
transition={{ duration: 0.25 }}
38+
>
39+
We <span className="text-secondary">Explore</span>
40+
</motion.div>
41+
</div>
42+
</div>
43+
</div>
5144
);
5245
};
5346

0 commit comments

Comments
 (0)