From fae99f6a407de70fdba6029e45c194fb241c3433 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Sat, 3 Aug 2024 18:59:56 +0530 Subject: Fixed routing issue with POPUP --- panel/src/App.jsx | 33 +++++++++++++++++++++------------ panel/src/components/Navbar.jsx | 20 +++++++++++++------- panel/src/components/PrivateRoute.jsx | 4 ++++ panel/src/contexts/AuthContext.jsx | 8 +++++++- 4 files changed, 45 insertions(+), 20 deletions(-) (limited to 'panel/src') diff --git a/panel/src/App.jsx b/panel/src/App.jsx index 6d88aaf..6a09905 100644 --- a/panel/src/App.jsx +++ b/panel/src/App.jsx @@ -7,24 +7,33 @@ import Dashboard from './pages/Dashboard'; import ManageAds from './pages/ManageAds'; import Roles from './pages/Roles'; import PrivateRoute from './components/PrivateRoute'; -import { AuthProvider } from './contexts/AuthContext'; +import { AuthProvider, useAuth } from './contexts/AuthContext'; import 'bootstrap/dist/css/bootstrap.min.css'; import './tailwind.css'; +const AppRoutes = () => { + const { currentUser } = useAuth(); + + return ( + + : } /> + } /> + } /> + } /> + }> + } /> + } /> + } /> + } /> + + + ); +}; + function App() { return ( - - } /> - } /> - } /> - } /> - }> - } /> - } /> - } /> - - + ); } diff --git a/panel/src/components/Navbar.jsx b/panel/src/components/Navbar.jsx index d9632e3..938e00a 100644 --- a/panel/src/components/Navbar.jsx +++ b/panel/src/components/Navbar.jsx @@ -1,5 +1,5 @@ -import React, { useState, useEffect } from 'react'; -import { Link } from 'react-router-dom'; +import React, { useState } from 'react'; +import { Link, useNavigate } from 'react-router-dom'; import MenuIcon from '@mui/icons-material/Menu'; import CloseIcon from '@mui/icons-material/Close'; import $ from 'jquery'; @@ -9,6 +9,13 @@ import './Navbar.css'; const Navbar = () => { const [isMenuOpen, setIsMenuOpen] = useState(false); + const navigate = useNavigate(); + + const handleLinkClick = (path) => { + $.magnificPopup.close(); + setIsMenuOpen(false); + navigate(path); + }; const toggleMenu = () => { if (!isMenuOpen) { @@ -27,7 +34,6 @@ const Navbar = () => { } else { $.magnificPopup.close(); } - setIsMenuOpen(!isMenuOpen); }; return ( @@ -44,10 +50,10 @@ const Navbar = () => { diff --git a/panel/src/components/PrivateRoute.jsx b/panel/src/components/PrivateRoute.jsx index e2c502d..341625e 100644 --- a/panel/src/components/PrivateRoute.jsx +++ b/panel/src/components/PrivateRoute.jsx @@ -5,6 +5,10 @@ import { useAuth } from '../contexts/AuthContext'; const PrivateRoute = () => { const { currentUser } = useAuth(); + if (currentUser === undefined) { + return
Loading...
; // Or a spinner/loading component + } + return currentUser ? : ; }; diff --git a/panel/src/contexts/AuthContext.jsx b/panel/src/contexts/AuthContext.jsx index cf8c7b5..f4f9383 100644 --- a/panel/src/contexts/AuthContext.jsx +++ b/panel/src/contexts/AuthContext.jsx @@ -10,10 +10,12 @@ export const useAuth = () => { export const AuthProvider = ({ children }) => { const [currentUser, setCurrentUser] = useState(null); + const [loading, setLoading] = useState(true); useEffect(() => { const unsubscribe = onAuthStateChanged(auth, (user) => { setCurrentUser(user); + setLoading(false); }); return unsubscribe; @@ -23,5 +25,9 @@ export const AuthProvider = ({ children }) => { currentUser, }; - return {children}; + return ( + + {!loading && children} + + ); }; -- cgit v1.2.3-59-g8ed1b