1
1
import React , { useEffect , useState } from 'react' ;
2
- // import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
2
+ import { BrowserRouter as Router , Routes , Route , Navigate , useLocation } from 'react-router-dom' ;
3
+ import NProgress from 'nprogress' ;
4
+ import 'nprogress/nprogress.css' ;
3
5
import './App.css' ;
4
6
import './index.css' ;
5
- import {
6
- BrowserRouter as Router ,
7
- Routes ,
8
- Route ,
9
- Navigate ,
10
- useLocation
11
- } from 'react-router-dom' ;
12
7
import SearchResults from './components/search' ;
13
8
import Login from './components/login' ;
14
9
import SignUp from './components/register' ;
@@ -23,62 +18,65 @@ import Dashboard from './components/dashboard';
23
18
import courses from './components/courseData' ;
24
19
import Footer from './components/Footer' ;
25
20
26
- function App ( ) {
21
+ // Configure NProgress settings
22
+ NProgress . configure ( { showSpinner : false , speed : 500 , trickleSpeed : 200 } ) ;
23
+
24
+ const App = ( ) => {
25
+ const location = useLocation ( ) ;
27
26
const [ user , setUser ] = useState ( null ) ;
28
27
28
+ useEffect ( ( ) => {
29
+ NProgress . start ( ) ;
30
+
31
+ const timeout = setTimeout ( ( ) => {
32
+ NProgress . done ( ) ;
33
+ } , 200 ) ;
34
+
35
+ return ( ) => {
36
+ clearTimeout ( timeout ) ;
37
+ NProgress . done ( ) ;
38
+ } ;
39
+ } , [ location ] ) ;
40
+
41
+ // Firebase authentication check
29
42
useEffect ( ( ) => {
30
43
const unsubscribe = auth . onAuthStateChanged ( ( user ) => {
31
- setUser ( user ) ; // Set user when logged in
44
+ setUser ( user ) ;
32
45
} ) ;
33
-
34
- return ( ) => unsubscribe ( ) ; // Clean up on unmount
46
+ return ( ) => unsubscribe ( ) ;
35
47
} , [ ] ) ;
36
- // Handle redirects from GitHub Pages 404 fallback
37
- // function RedirectWithState() {
38
- // const location = useLocation();
39
- // useEffect(() => {
40
- // const redirectPath = new URLSearchParams(location.search).get('redirect');
41
- // if (redirectPath) {
42
- // window.history.replaceState({}, '', redirectPath);
43
- // }
44
- // }, [location]);
45
- // return null;
46
- // }
47
48
48
49
return (
49
- < Router basename = { import . meta. env . BASE_URL } >
50
- { /* <RedirectWithState /> */ }
51
- < div className = "App" >
52
- { /* Pass user status as loggedin prop to Navbar */ }
53
- < Navbar loggedin = { user ? 'true' : 'false' } />
54
- < div className = "auth-wrapper" >
55
- < div className = "auth-inner" >
56
-
57
- < Routes >
58
- { /* Redirect to profile if the user is logged in */ }
59
- < Route path = "/" element = { user ? < Navigate to = "/profile" /> : < Login /> } />
60
- < Route path = "/home" element = { < Home /> } />
61
- < Route
62
- path = "/login"
63
- element = { user ? < Navigate to = "/profile" /> : < Login /> }
64
- />
65
- < Route path = "/register" element = { < SignUp /> } />
66
- < Route
67
- path = "/profile"
68
- element = { user ? < Profile /> : < Navigate to = "/login" /> }
69
- />
70
- < Route path = "/courses/:courseName" element = { < CourseDetail /> } />
71
- < Route path = "/" element = { < Dashboard courses = { courses } /> } />
72
- < Route path = "/search" element = { < SearchResults /> } />
73
-
74
- </ Routes >
75
- < ToastContainer />
76
- </ div >
50
+ < div className = "App" >
51
+ < Navbar loggedin = { user ? 'true' : 'false' } />
52
+ < div className = "auth-wrapper" >
53
+ < div className = "auth-inner" >
54
+ < Routes >
55
+ { /* Redirect to profile if user is logged in */ }
56
+ < Route path = "/" element = { user ? < Navigate to = "/profile" /> : < Login /> } />
57
+ < Route path = "/home" element = { < Home /> } />
58
+ < Route path = "/login" element = { user ? < Navigate to = "/profile" /> : < Login /> } />
59
+ < Route path = "/register" element = { < SignUp /> } />
60
+ < Route path = "/profile" element = { user ? < Profile /> : < Navigate to = "/login" /> } />
61
+ < Route path = "/courses/:courseName" element = { < CourseDetail /> } />
62
+ < Route path = "/dashboard" element = { < Dashboard courses = { courses } /> } />
63
+ < Route path = "/search" element = { < SearchResults /> } />
64
+ </ Routes >
65
+ < ToastContainer />
77
66
</ div >
78
67
</ div >
79
- < Footer />
68
+ < Footer />
69
+ </ div >
70
+ ) ;
71
+ } ;
72
+
73
+ const WrappedApp = ( ) => {
74
+ return (
75
+ < Router >
76
+ < App />
80
77
</ Router >
81
78
) ;
82
- }
79
+ } ;
80
+
81
+ export default WrappedApp ;
83
82
84
- export default App ;
0 commit comments