url-minify/frontend/components/NavBar/index.js

201 lines
5.7 KiB
JavaScript
Raw Normal View History

2022-02-15 17:18:05 +00:00
import React, { useContext } from 'react'
2022-02-15 14:49:59 +00:00
import {
Avatar,
Box,
Button,
Container,
IconButton,
Menu,
MenuItem,
Toolbar,
Tooltip,
Typography,
alpha,
2022-02-15 17:18:05 +00:00
} from '@mui/material'
import GitHubIcon from '@mui/icons-material/GitHub'
import MenuIcon from '@mui/icons-material/Menu'
import NavbarStyle from './Navbar.style'
import Logo from './Logo'
import UserAuth, { UserContext } from 'helpers/user/usercontext'
import Link from 'next/link'
const settings = ['Profile', 'Account', 'Dashboard', 'Logout']
import NotFound from '@pages/404'
2022-02-01 15:50:14 +00:00
function Index(props) {
2022-02-15 17:18:05 +00:00
const [anchorElNav, setAnchorElNav] = React.useState(null)
const [anchorElUser, setAnchorElUser] = React.useState(null)
2022-02-15 14:49:59 +00:00
const handleOpenNavMenu = (event) => {
2022-02-15 17:18:05 +00:00
setAnchorElNav(event.currentTarget)
}
2022-02-15 14:49:59 +00:00
const handleOpenUserMenu = (event) => {
2022-02-15 17:18:05 +00:00
setAnchorElUser(event.currentTarget)
}
2022-02-15 14:49:59 +00:00
const handleCloseNavMenu = () => {
2022-02-15 17:18:05 +00:00
setAnchorElNav(null)
}
2022-02-01 15:50:14 +00:00
2022-02-15 14:49:59 +00:00
const handleCloseUserMenu = () => {
2022-02-15 17:18:05 +00:00
setAnchorElUser(null)
}
2022-02-01 15:50:14 +00:00
2022-02-15 17:18:05 +00:00
const { user, login, logout } = useContext(UserAuth)
2022-02-01 15:50:14 +00:00
2022-02-15 14:49:59 +00:00
return (
<NavbarStyle
position="relative"
2022-02-15 17:18:05 +00:00
sx={{ bgcolor: alpha('#000000', 0.5), m: '0px' }}
2022-02-15 14:49:59 +00:00
>
<Container maxWidth="xl">
<Toolbar disableGutters="false">
2022-02-15 17:18:05 +00:00
<Typography variant="h4" sx={{ fontWeight: 'bold' }}>
2022-02-15 14:49:59 +00:00
URL MINIFY
</Typography>
<Box
sx={{
flexGrow: 1,
2022-02-15 17:18:05 +00:00
flexDirection: 'row-reverse',
display: { xs: 'flex', md: 'none' },
2022-02-15 14:49:59 +00:00
}}
>
<IconButton
size="large"
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
onClick={handleOpenNavMenu}
color="inherit"
>
<MenuIcon />
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorElNav}
anchorOrigin={{
2022-02-15 17:18:05 +00:00
vertical: 'bottom',
horizontal: 'left',
2022-02-15 14:49:59 +00:00
}}
keepMounted
transformOrigin={{
2022-02-15 17:18:05 +00:00
vertical: 'top',
horizontal: 'left',
2022-02-15 14:49:59 +00:00
}}
open={Boolean(anchorElNav)}
onClose={handleCloseNavMenu}
sx={{
2022-02-15 17:18:05 +00:00
display: { xs: 'block', md: 'none' },
2022-02-15 14:49:59 +00:00
}}
>
<MenuItem onClick={handleCloseNavMenu}>
<a
href="https://github.com/BRAVO68WEB/url-minify"
2022-02-15 17:18:05 +00:00
target={'_blank'}
2022-02-15 14:49:59 +00:00
>
2022-02-15 17:18:05 +00:00
<Typography textAlign="center" sx={{ display: 'flex' }}>
2022-02-15 14:49:59 +00:00
<GitHubIcon fontSize="small" />
GitHub
</Typography>
</a>
</MenuItem>
<MenuItem onClick={handleCloseNavMenu}>
<a href="NotFound">
<Typography textAlign="center" sx={{ display: 'flex' }}>
CREDITS
</Typography>
</a>
2022-02-15 14:49:59 +00:00
</MenuItem>
</Menu>
</Box>
2022-02-01 15:50:14 +00:00
2022-02-15 14:49:59 +00:00
<Box
sx={{
flexGrow: 1,
2022-02-15 17:18:05 +00:00
flexDirection: 'row-reverse',
gap: '10px',
px: '20px',
display: { xs: 'none', md: 'flex' },
2022-02-15 14:49:59 +00:00
}}
>
<a
href="https://github.com/BRAVO68WEB/url-minify"
2022-02-15 17:18:05 +00:00
target={'_blank'}
2022-02-15 14:49:59 +00:00
>
<Button
onClick={handleCloseNavMenu}
sx={{
2022-02-15 17:18:05 +00:00
color: 'white',
display: 'flex',
gap: '10px',
fontSize: 'h5.fontSize',
fontFamily: 'sans-serif',
fontStyle: 'bold',
textTransform: 'capitalize',
fontWeight: 'bold',
2022-02-15 14:49:59 +00:00
}}
>
<GitHubIcon fontSize="large" />
GitHub
</Button>
</a>
<a href="NotFound">
<Button
onClick={handleCloseNavMenu}
sx={{
color: 'white',
display: 'block',
fontSize: 'h5.fontSize',
}}
>
CREDITS
</Button>
</a>
2022-02-15 14:49:59 +00:00
</Box>
2022-02-01 15:50:14 +00:00
2022-02-15 14:49:59 +00:00
{user ? (
<Box sx={{ flexGrow: 0 }}>
<Tooltip title="Open settings">
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
<Avatar
alt="Remy Sharp"
src="/static/images/avatar/2.jpg"
sx={{ width: 50, height: 50 }}
/>
</IconButton>
</Tooltip>
<Menu
2022-02-15 17:18:05 +00:00
sx={{ mt: '45px' }}
2022-02-15 14:49:59 +00:00
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
2022-02-15 17:18:05 +00:00
vertical: 'top',
horizontal: 'right',
2022-02-15 14:49:59 +00:00
}}
keepMounted
transformOrigin={{
2022-02-15 17:18:05 +00:00
vertical: 'top',
horizontal: 'right',
2022-02-15 14:49:59 +00:00
}}
open={Boolean(anchorElUser)}
onClose={handleCloseUserMenu}
>
{settings.map((setting) => (
<MenuItem key={setting} onClick={handleCloseUserMenu}>
<Typography textAlign="center">{setting}</Typography>
</MenuItem>
))}
</Menu>
</Box>
) : (
<Typography onClick={login}>
<Link href="./login">LOGIN</Link>
</Typography>
)}
</Toolbar>
</Container>
</NavbarStyle>
2022-02-15 17:18:05 +00:00
)
2022-02-01 15:50:14 +00:00
}
2022-02-15 17:18:05 +00:00
export default Index