File tree Expand file tree Collapse file tree 4 files changed +71
-15
lines changed
Expand file tree Collapse file tree 4 files changed +71
-15
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 1+ import { useState } from "react" ;
12import { AnimatePresence } from "framer-motion" ;
23import { HashRouter as Router , Routes , Route } from "react-router-dom" ;
34import { ToastContainer } from "react-toastify" ;
45import routes from "@/routes/index" ;
56import Navbar from "@/components/Navbar/index" ;
67import Cursor from "./components/Cursor" ;
78import CursorVariantProvider from "@/context/CursorVariantProvider" ;
9+ import Loader from "@/components/Loader" ;
810
911const navLinks = [
1012 { name : "About Us" , path : "/about-us" } ,
@@ -15,24 +17,34 @@ const navLinks = [
1517] ;
1618
1719function 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 ) ;
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -4,8 +4,15 @@ import About from "@/pages/About/index";
44import Gallery from "@/pages/Gallery/Gallery" ;
55import Contact from "@/pages/Contact" ;
66import PageNotFound from "../pages/PageNotFound" ;
7+ import Loader from "@/components/Loader" ;
78
89const routes = [
10+ {
11+ label : "Loader" ,
12+ path : "/loader" ,
13+ requireAuth : false ,
14+ render : < Loader /> ,
15+ } ,
916 {
1017 label : "Contact" ,
1118 path : "/contact" ,
You can’t perform that action at this time.
0 commit comments