-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
navbar #80
Merged
Merged
navbar #80
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
641177e
navbar
JibrilExe b474f58
changes
JibrilExe 6d1e576
oops
JibrilExe fb3dfa0
close bar on redirect
JibrilExe 5ffca16
linter conflicts for component function
JibrilExe db1401f
merge en isloggedin
JibrilExe 12a580e
scalability matters
JibrilExe fd2142a
useEffect to check login state and adjust link item list
JibrilExe fedfad7
a little more readable
JibrilExe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,103 @@ | ||
import { | ||
AppBar, | ||
Box, | ||
Button, | ||
IconButton, | ||
Toolbar, | ||
Typography, | ||
} from "@mui/material"; | ||
import MenuIcon from "@mui/icons-material/Menu"; | ||
import { useTranslation } from "react-i18next"; | ||
import { AppBar, Box, Button, Drawer, Grid, IconButton, List, ListItemButton, ListItemText, Toolbar, Typography } from "@mui/material"; | ||
import { Menu } from "@mui/icons-material"; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import { useState } from "react"; | ||
|
||
/** | ||
* The header component for the application that will be rendered at the top of the page. | ||
* @returns - The header component | ||
* Renders the header component. | ||
* @returns JSX.Element representing the header. | ||
*/ | ||
export function Header(): JSX.Element { | ||
const { t } = useTranslation(); | ||
const location = useLocation(); | ||
const [open, setOpen] = useState(false); | ||
|
||
let listItems = [ | ||
{link: "/", text: t("homepage")} | ||
]; | ||
|
||
if(isLoggedIn()) { | ||
listItems = listItems.concat([ | ||
{link: "/projects", text: t("myProjects")}, | ||
{link: "/courses", text: t("myCourses")} | ||
]); | ||
} | ||
|
||
const title = getTitle(location.pathname, t); | ||
|
||
return ( | ||
<Box sx={{ flexGrow: 1 }}> | ||
<AppBar position="sticky"> | ||
<Toolbar> | ||
<IconButton size="large" color="inherit"> | ||
<MenuIcon /> | ||
<Toolbar disableGutters> | ||
<IconButton edge="start" onClick={() => setOpen(!open)} sx={{ color: "white", marginLeft: 0 }}> | ||
<Menu style={{fontSize:"2rem"}} /> | ||
</IconButton> | ||
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}> | ||
{t('home')} | ||
{title} | ||
</Typography> | ||
<Button color="inherit">Login</Button> | ||
<Box sx={{ flexGrow: 1 }} /> | ||
<Button color="inherit">{t('login')}</Button> | ||
</Toolbar> | ||
</AppBar> | ||
<DrawerMenu open={open} onClose={() => setOpen(false)} listItems={listItems}/> | ||
</Box> | ||
); | ||
} | ||
/** | ||
* @returns Whether a user is logged in or not. | ||
*/ | ||
function isLoggedIn() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the title based on the given pathname. | ||
* @param pathname - The current pathname. | ||
* @param t - The translation function. | ||
* @returns The title. | ||
*/ | ||
function getTitle(pathname: string, t: (key: string) => string): string { | ||
switch(pathname) { | ||
case '/': return t('home'); | ||
case '/login': return t('login'); | ||
case '/courses': return t('myCourses'); | ||
case '/projects': return t('myProjects'); | ||
default: return t('home'); | ||
} | ||
} | ||
|
||
/** | ||
* Renders the drawer menu component. | ||
* @param open - Whether the drawer menu is open or not. | ||
* @param onClose - Function to handle the close event of the drawer menu. | ||
* @param listItems - Array of objects representing the list items in the drawer menu. | ||
* @returns The Side Bar | ||
*/ | ||
function DrawerMenu({ open, onClose, listItems }: { open: boolean, onClose: () => void, listItems: { link: string, text: string }[] }) { | ||
|
||
return ( | ||
<Drawer open={open} anchor="left" onClose={onClose}> | ||
<Grid container direction="column" sx={{ | ||
width: 250, | ||
height: "100%", | ||
backgroundColor: "primary.main" | ||
}}> | ||
<Grid item container direction="row" alignItems="flex-start"> | ||
<IconButton onClick={onClose} sx={{ | ||
color: "white" | ||
}}> | ||
<Menu style={{fontSize:"2rem"}} /> | ||
</IconButton> | ||
</Grid> | ||
<List> | ||
{listItems.map((listItem, index) => ( | ||
<ListItemButton key={index} component={Link} to={listItem.link} role="listitem" onClick={onClose}> | ||
<ListItemText primary={listItem.text} sx={{color:"white"}} /> | ||
</ListItemButton> | ||
))} | ||
</List> | ||
</Grid> | ||
</Drawer> | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this in an effect. Everything that's not in an effect will be executed unnecessarily on every state change or mount