Skip to content
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 9 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
"jsdoc/check-access": 1,
"tsdoc/syntax": "warn",
"jsdoc/check-alignment": 1,
"jsdoc/check-param-names": 1,
"jsdoc/check-param-names": 0,
"jsdoc/check-property-names": 1,
"jsdoc/check-tag-names": 1,
"jsdoc/check-types": 1,
Expand All @@ -37,10 +37,10 @@ module.exports = {
"jsdoc/no-multi-asterisks": 1,
"jsdoc/no-undefined-types": 1,
"jsdoc/require-jsdoc": 1,
"jsdoc/require-param": 1,
"jsdoc/require-param": 0,
"jsdoc/require-param-description": 1,
"jsdoc/require-param-name": 1,
"jsdoc/require-param-type": 1,
"jsdoc/require-param-type": 0,
"jsdoc/require-property": 1,
"jsdoc/require-property-description": 1,
"jsdoc/require-property-name": 1,
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/logo_ugent.png" />
Expand Down
3 changes: 3 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
"@mui/icons-material": "^5.15.10",
"@mui/material": "^5.15.10",
"@mui/styled-engine-sc": "^6.0.0-alpha.16",
"i18next-browser-languagedetector": "^7.2.0",
"i18next-http-backend": "^2.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.1.0",
"react-router-dom": "^6.22.1",
"styled-components": "^6.1.8"
},
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Home from "./pages/home/Home";
import { BrowserRouter,Route,Routes } from "react-router-dom";
import { Header } from "./components/Header/Header";

import Home from "./pages/home/Home";
/**
* This component is the main application component that will be rendered by the ReactDOM.
* @returns - The main application component
Expand All @@ -16,5 +15,4 @@ function App(): JSX.Element {
</BrowserRouter>
);
}

export default App;
export default App;
104 changes: 87 additions & 17 deletions frontend/src/components/Header/Header.tsx
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()) {
Copy link
Contributor

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

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>
);
}