1
1
import React , { useEffect , useState } from 'react' ;
2
- import { BrowserRouter as Router , Routes , Route , Navigate , useLocation } from 'react-router-dom' ;
3
- import NProgress from 'nprogress' ;
4
- import 'nprogress/nprogress.css' ;
2
+ // import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
5
3
import './App.css' ;
6
4
import './index.css' ;
5
+ import {
6
+ BrowserRouter as Router ,
7
+ Routes ,
8
+ Route ,
9
+ Navigate ,
10
+ useLocation
11
+ } from 'react-router-dom' ;
7
12
import SearchResults from './components/search' ;
8
13
import Login from './components/login' ;
9
14
import SignUp from './components/register' ;
@@ -18,65 +23,62 @@ import Dashboard from './components/dashboard';
18
23
import courses from './components/courseData' ;
19
24
import Footer from './components/Footer' ;
20
25
21
- // Configure NProgress settings
22
- NProgress . configure ( { showSpinner : false , speed : 500 , trickleSpeed : 200 } ) ;
23
-
24
- const App = ( ) => {
25
- const location = useLocation ( ) ;
26
+ function App ( ) {
26
27
const [ user , setUser ] = useState ( null ) ;
27
28
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
42
29
useEffect ( ( ) => {
43
30
const unsubscribe = auth . onAuthStateChanged ( ( user ) => {
44
- setUser ( user ) ;
31
+ setUser ( user ) ; // Set user when logged in
45
32
} ) ;
46
- return ( ) => unsubscribe ( ) ;
33
+
34
+ return ( ) => unsubscribe ( ) ; // Clean up on unmount
47
35
} , [ ] ) ;
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
+ // }
48
47
49
48
return (
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 />
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 >
66
77
</ div >
67
78
</ div >
68
- < Footer />
69
- </ div >
70
- ) ;
71
- } ;
72
-
73
- const WrappedApp = ( ) => {
74
- return (
75
- < Router >
76
- < App />
79
+ < Footer />
77
80
</ Router >
78
81
) ;
79
- } ;
80
-
81
- export default WrappedApp ;
82
+ }
82
83
84
+ export default App ;
0 commit comments