Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x | import React, { useState, useEffect } from "react";
import "./NavBar.scss";
import { NavLink, useNavigate } from "react-router-dom";
import { Button, IconButton, Drawer, Typography, useMediaQuery, useTheme } from "@mui/material";
import MenuIcon from "@mui/icons-material/Menu";
import CloseIcon from "@mui/icons-material/Close";
// import SchoolIcon from "@mui/icons-material/School";
import MVP_LOGO from "@/assets/logo/mvp_logo2.png";
import appVersion from "/version.txt?raw";
const NavBar = () => {
const navigate = useNavigate();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
const [drawerOpen, setDrawerOpen] = useState(false);
const [isScrolled, setIsScrolled] = useState(false);
useEffect(() => {
const handleScroll = () => {
setIsScrolled(window.scrollY > 10);
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);
const toggleDrawer = (open) => (event) => {
if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) {
return;
}
setDrawerOpen(open);
};
const navItems = [
{ label: "Home", path: "/", id: "nav-home" },
{ label: "About", path: "/about", id: "nav-about" },
{ label: "Contact", path: "/contact", id: "nav-contact" },
];
const renderDesktopNav = () => (
<div className={`navbar-content${isScrolled ? " scrolled" : ""}`}>
<div className="navbar-container">
<div className="logo-section" onClick={() => navigate("/")}>
<img src={MVP_LOGO} className="logo-icon" alt="mvp_logo" />
<div className="logo-text-group">
<Typography variant="h6" className="logo-text" sx={{ textTransform: "none" }}>
EruditionTX
</Typography>
<Typography className="logo-version">v{appVersion.trim()}</Typography>
</div>
</div>
<div className="nav-links">
{navItems.map((item) => (
<NavLink
key={item.id}
id={item.id}
to={item.path}
className={({ isActive }) => (isActive ? "nav-link active" : "nav-link")}
>
<Typography variant="body1">{item.label}</Typography>
</NavLink>
))}
</div>
<div className="nav-actions">
<Button
id="landing-page-navbar-button-login"
variant="contained"
color="primary"
onClick={() => navigate("/login")}
className="login-button"
>
Login
</Button>
</div>
</div>
</div>
);
const renderMobileNav = () => (
<div className={`navbar-content mobile${isScrolled ? " scrolled" : ""}`}>
<div className="navbar-container">
<div className="logo-section" onClick={() => navigate("/")}>
<img src={MVP_LOGO} className="logo-icon" alt="mvp_logo" />
<div className="logo-text-group">
<Typography variant="h6" className="logo-text">
EruditionTX
</Typography>
<Typography className="logo-version">v{appVersion.trim()}</Typography>
</div>
</div>
<IconButton
edge="end"
color="inherit"
aria-label="menu"
onClick={toggleDrawer(true)}
className="menu-button"
>
<MenuIcon />
</IconButton>
</div>
<Drawer
anchor="right"
open={drawerOpen}
onClose={toggleDrawer(false)}
PaperProps={{
className: "mobile-drawer-paper",
}}
>
<div className="mobile-drawer">
<div className="drawer-header">
<div className="drawer-header-logo">
<img src={MVP_LOGO} className="drawer-logo-icon" alt="mvp_logo" />
<div className="logo-text-group">
<Typography variant="h6" className="drawer-logo-text">
EruditionTX
</Typography>
<Typography className="logo-version">v{appVersion.trim()}</Typography>
</div>
</div>
<IconButton onClick={toggleDrawer(false)} className="drawer-close-btn">
<CloseIcon />
</IconButton>
</div>
<nav className="drawer-nav">
{navItems.map((item) => (
<NavLink
key={item.id}
id={`mobile-${item.id}`}
to={item.path}
className={({ isActive }) => (isActive ? "mobile-nav-link active" : "mobile-nav-link")}
onClick={toggleDrawer(false)}
>
{item.label}
</NavLink>
))}
</nav>
<div className="drawer-footer">
<Button
id="mobile-nav-login-button"
variant="contained"
fullWidth
className="drawer-login-btn"
onClick={() => {
navigate("/login");
setDrawerOpen(false);
}}
>
Login
</Button>
</div>
</div>
</Drawer>
</div>
);
return isMobile ? renderMobileNav() : renderDesktopNav();
};
export default NavBar;
|