import React from "react"; import { Link } from "react-router-dom"; import { logOut } from "../../reducers/auth"; import { useAppDispatch, useAppSelector } from "../../utils/hooks"; import AppBar from "@mui/material/AppBar"; import Box from "@mui/material/Box"; import Toolbar from "@mui/material/Toolbar"; import IconButton from "@mui/material/IconButton"; import Typography from "@mui/material/Typography"; import Menu from "@mui/material/Menu"; import Container from "@mui/material/Container"; import Button from "@mui/material/Button"; import MenuItem from "@mui/material/MenuItem"; import MenuIcon from "@mui/icons-material/Menu"; import AdbIcon from "@mui/icons-material/Adb"; const linkStyle = { color: "inherit", textDecoration: "none" }; const Navbar = () => { const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated); const dispatch = useAppDispatch(); const [anchorElNav, setAnchorElNav] = React.useState( null, ); const handleOpenNavMenu = (event: React.MouseEvent) => { setAnchorElNav(event.currentTarget); }; const handleCloseNavMenu = () => { setAnchorElNav(null); }; const authLinks = [ { id: 1, to: "/profiles", message: "Developers", }, { id: 2, to: "/posts", message: "Posts", }, { id: 3, to: "/dashboard", message: "Profile", }, ]; const guestLinks = [ { id: 1, to: "/profiles", message: "Developers", }, { id: 2, to: "/register", message: "Register", }, { id: 3, to: "/login", message: "Login", }, ]; return ( {/*Icon for big dislay*/} {/*LOGO link for bi display*/} DevConnect {/* Small display menu*/} {/* Small display button */} {/* The actual menu that pops when you click the button */} {isAuthenticated ? (
{" "} {authLinks.map((el) => ( {el.message} ))} dispatch(logOut())} href="#!" > Logout
) : ( guestLinks.map((el) => ( {el.message} )) )}
{/* Icon for small display */} {/* LOGO text link small display*/} DevConnect {/* Menu bar for big display*/} {isAuthenticated ? ( <> {authLinks.map((el) => ( ))} ) : ( guestLinks.map((el) => ( )) )}
); }; export default Navbar;