From a0398286c3eb941c3192098f0db167097afea9cc Mon Sep 17 00:00:00 2001 From: PrathamX595 Date: Sun, 30 Jun 2024 18:37:20 +0530 Subject: [PATCH] Frontend: Improved Navbar by dynamic links The navbar buttons are generated based on the data in an array. This allows for easier changes to the navbar. The shadow overlay on the rest of the screen is also amended and a drop shadow is added on the navbar. Fixes #122 --- frontend/src/Navbar.tsx | 142 +++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 61 deletions(-) diff --git a/frontend/src/Navbar.tsx b/frontend/src/Navbar.tsx index 0550fb5..52eb5c8 100644 --- a/frontend/src/Navbar.tsx +++ b/frontend/src/Navbar.tsx @@ -127,15 +127,43 @@ const rules = ( ); + const Navbar: React.FC = () => { const [sidebarOpen, setSidebarOpen] = useState(false); + const links = [ + { + text: 'Login', + type: 'link', + callback: () => navigate('/login'), + }, + { + text: 'Logout', + type: 'link', + callback: () => auth.logout(), + }, + { + text: 'About Us', + type: 'modal', + callback: () => + modal.show('aboutUsModal', aboutUs, 'large', [ + { text: 'Close', type: 'submit' }, + ]), + }, + { + text: 'Rules', + type: 'modal', + callback: () => + modal.show('rulesModal', rules, 'large', [ + { text: 'Close', type: 'submit' }, + ]), + }, + ]; const auth = useAuth(); const modal = useModal(); const navigate = useNavigate(); const location = useLocation(); const showLoginBtn = location.pathname !== '/login' && location.pathname !== '/signup'; - const toggleMenu = () => { setSidebarOpen(!sidebarOpen); }; @@ -199,9 +227,7 @@ const Navbar: React.FC = () => {
+
+ {links.map((link, index) => { + if ( + link.text === 'Logout' || + link.type === 'modal' + ) { + return ( +
+ +
+ ); + } + })} +
) : ( <> - +
+ {links.map((link, index) => { + if ( + link.text === 'Login' || + link.type === 'modal' + ) { + return ( +
+ +
+ ); + } + })} +
)} -
- -
-
- -