Skip to content

Commit 9de985a

Browse files
committed
add progress
1 parent 7004683 commit 9de985a

File tree

4 files changed

+75
-59
lines changed

4 files changed

+75
-59
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"bootstrap": "^5.3.3",
1515
"firebase": "^10.13.1",
1616
"marked": "^14.1.2",
17+
"nprogress": "^0.2.0",
1718
"react": "^18.3.1",
1819
"react-dom": "^18.3.1",
1920
"react-router-dom": "^6.26.2",

src/App.css

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
:root{
2+
--primary-color:rgb(186, 22, 163);
3+
}
14
.App {
25
/* text-align: center; */
36
}
@@ -24,7 +27,7 @@
2427
color: white;
2528
}
2629
.lnk {
27-
color: rgb(186 22 163) ;
30+
color: var(--primary-color) ;
2831
text-decoration: none ;
2932
}
3033
.clk{
@@ -43,13 +46,20 @@ background: rgb(186 22 163) !important;
4346
transform: rotate(360deg);
4447
}
4548
}
46-
/* Default state for search input */
4749
.input-group .form-control {
4850
width: 150px;
4951
transition: width 0.3s ease-in-out;
5052
}
51-
52-
/* Expanded state when the input is focused */
5353
.search-expanded .form-control {
54-
width: 300px; /* You can adjust this width */
54+
width: 300px;
55+
}
56+
#nprogress .bar {
57+
background: var(--primary-color);
58+
59+
#nprogress .spinner-icon {
60+
border-top-color: var(--primary-color);
61+
border-left-color: var(--primary-color);
62+
}
63+
#nprogress .peg {
64+
box-shadow: 0 0 10px var(--primary-color), 0 0 5px var(--primary-color);
5565
}

src/App.jsx

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
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';
35
import './App.css';
46
import './index.css';
5-
import {
6-
BrowserRouter as Router,
7-
Routes,
8-
Route,
9-
Navigate,
10-
useLocation
11-
} from 'react-router-dom';
127
import SearchResults from './components/search';
138
import Login from './components/login';
149
import SignUp from './components/register';
@@ -23,62 +18,65 @@ import Dashboard from './components/dashboard';
2318
import courses from './components/courseData';
2419
import Footer from './components/Footer';
2520

26-
function App() {
21+
// Configure NProgress settings
22+
NProgress.configure({ showSpinner: false, speed: 500, trickleSpeed: 200 });
23+
24+
const App = () => {
25+
const location = useLocation();
2726
const [user, setUser] = useState(null);
2827

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
2942
useEffect(() => {
3043
const unsubscribe = auth.onAuthStateChanged((user) => {
31-
setUser(user); // Set user when logged in
44+
setUser(user);
3245
});
33-
34-
return () => unsubscribe(); // Clean up on unmount
46+
return () => unsubscribe();
3547
}, []);
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-
// }
4748

4849
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 />
7766
</div>
7867
</div>
79-
<Footer />
68+
<Footer />
69+
</div>
70+
);
71+
};
72+
73+
const WrappedApp = () => {
74+
return (
75+
<Router>
76+
<App />
8077
</Router>
8178
);
82-
}
79+
};
80+
81+
export default WrappedApp;
8382

84-
export default App;

0 commit comments

Comments
 (0)