Skip to content

Commit

Permalink
feat: Add Sidebar component and update dependencies (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Dec 24, 2023
1 parent 6d795a8 commit 95a3820
Show file tree
Hide file tree
Showing 8 changed files with 7,034 additions and 3,269 deletions.
10,142 changes: 6,935 additions & 3,207 deletions frontend/package-lock.json

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"@mui/icons-material": "5.15.1",
"@mui/lab": "5.0.0-alpha.157",
"@mui/material": "5.15.1",
"@react-buddy/ide-toolbox": "^2.4.0",
"@react-buddy/palette-mui": "^5.0.1",
"@react-keycloak/web": "^3.4.0",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/react": "14.1.2",
Expand Down Expand Up @@ -42,12 +44,19 @@
"build": "tsc && vite build",
"dev": "vite",
"prettier": "prettier --write \"src/**/*.tsx\"",
"lint": "eslint . --ext .tsx",
"codegen": "graphql-codegen --config codegen.ts"
},
"eslintConfig": {
"overrides": [
{
"files": [
"src/**/*.tsx"
]
}
],
"extends": [
"react-app",
"react-app/jest"
"react-app"
]
},
"browserslist": {
Expand All @@ -63,11 +72,14 @@
]
},
"devDependencies": {
"eslint-config-react-app": "^7.0.1",
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/client-preset": "4.1.0",
"@graphql-codegen/introspection": "4.0.0",
"@types/babel__core": "^7.1.20",
"eslint": "^8.56.0",
"prettier": "^3.0.0",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vite-plugin-eslint": "^1.8.1"
}
}
2 changes: 1 addition & 1 deletion frontend/src/component/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Headline extends React.Component {
<Toolbar>
{buttons(pages)}
<div />
<LoginButton />
<LoginButton sx={{}} />
</Toolbar>
</AppBar>
);
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/component/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Button, Typography } from '@mui/material';
import { Button, SxProps, Theme, Typography } from '@mui/material';
import React from 'react';
import { useKeycloak } from '@react-keycloak/web';

export function LoginButton() {
interface LoginButtonProps {
sx: SxProps<Theme>;
}

export function LoginButton({ sx }: LoginButtonProps) {
const { keycloak } = useKeycloak();

const handleAuth = () => {
Expand Down Expand Up @@ -32,7 +36,7 @@ export function LoginButton() {
};

return (
<Button onClick={handleAuth} sx={{ margin: '5px' }}>
<Button onClick={handleAuth} sx={{ ...sx }}>
<Typography sx={{ color: 'white' }}>{getButtonText()}</Typography>
</Button>
);
Expand Down
65 changes: 65 additions & 0 deletions frontend/src/component/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Divider from '@mui/material/Divider';
import List from '@mui/material/List';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import MenuIcon from '@mui/icons-material/Menu';
import { LoginButton } from './LoginButton';
import { ListItemButton } from '@mui/material';
import { useNavigate } from 'react-router-dom';

export type LinkType = { title: string; url: string };

type Props = { links: LinkType[] };
interface ListItemsProps {
links: LinkType[];
}

function ListItems(props: ListItemsProps) {
const { links } = props;
const navigate = useNavigate();

return (
<>
{links.map(({ title, url }) => (
<ListItemButton key={url}>
<ListItemIcon>
<MenuIcon />
</ListItemIcon>
<ListItemText
primary={title}
sx={{ color: '#fff' }}
onClick={() => navigate(url)}
/>
</ListItemButton>
))}
</>
);
}

function Sidebar(props: Props) {
return (
<Box sx={{ width: 250, bgcolor: '#272727', height: '100vh' }}>
<Typography
variant="h6"
noWrap
component="div"
align="center"
sx={{ flexGrow: 1, p: 2 }}
>
Laughing-Train
</Typography>
<Divider />
<List>
<ListItems links={props.links} />
</List>
<LoginButton
sx={{ mx: 1, my: 1, color: '#fff', borderColor: '#fff', width: '90%' }}
/>
</Box>
);
}

export default Sidebar;
1 change: 1 addition & 0 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const themeOptions: ThemeOptions = {
},
},
spacing: 8,

components: {
MuiCard: {
styleOverrides: {
Expand Down
61 changes: 7 additions & 54 deletions frontend/src/pages/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,24 @@ import {
} from '@mui/material';
import { LoginButton } from '../component/LoginButton';

Check warning on line 12 in frontend/src/pages/PageLayout.tsx

View workflow job for this annotation

GitHub Actions / build

'LoginButton' is defined but never used
import { useNavigate } from 'react-router';

Check warning on line 13 in frontend/src/pages/PageLayout.tsx

View workflow job for this annotation

GitHub Actions / build

'useNavigate' is defined but never used
import Sidebar, { LinkType } from '../component/Sidebar';

interface NameProps {

Check warning on line 16 in frontend/src/pages/PageLayout.tsx

View workflow job for this annotation

GitHub Actions / build

'NameProps' is defined but never used
name: string;
}

function Name({ name }: NameProps) {
return (
<h1 style={{ fontSize: '20px', fontWeight: 'bold', margin: '0 0 0 5px' }}>
{name}
</h1>
);
}

function Navigation({ links }: NavigationProps) {
const navigate = useNavigate();
return (
<List>
{links.map((link) => (
<>
<ListItem
key={link.name}
onClick={() => navigate(link.href, { replace: true })}
>
<ListItemText primary={link.name} />
</ListItem>
<Divider sx={{ height: 1, backgroundColor: 'white' }} />
</>
))}
<LoginButton />
</List>
);
}
interface PageLayoutProps {
children: React.ReactNode;
}
interface Link {
name: string;
href: string;
}
interface NavigationProps {
links: Link[];
interface PageLayoutProps {
children: React.ReactNode;
}

export default function PageLayout({ children }: PageLayoutProps) {
const navigationItems: Link[] = [
{ name: 'Home', href: '/' },
{ name: 'Statistics', href: '/statistics' },
const navigationItems: LinkType[] = [
{ title: 'Home', url: '/' },
{ title: 'Statistics', url: '/statistics' },
];
return (
<div style={{ height: '100vh' }}>
Expand All @@ -67,25 +38,7 @@ export default function PageLayout({ children }: PageLayoutProps) {
style={{ height: 'calc(100%) ', flexWrap: 'nowrap' }}
>
<Grid item sx={{ width: '200px' }}>
<Box
sx={{
height: '100%',
bgcolor: '#272727',
overflow: 'hidden',
position: 'fixed',
}}
>
<AppBar
position="static"
elevation={0}
sx={{ bgcolor: '#272727', marginTop: '10px', marginLeft: '10px' }}
>
<Name name="Laughing-Train" />
<Toolbar>
<Navigation links={navigationItems} />
</Toolbar>
</AppBar>
</Box>
<Sidebar links={navigationItems} />
</Grid>
<Grid item xs={9} sx={{}}>
{children}
Expand Down
4 changes: 3 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import viteTsconfigPaths from 'vite-tsconfig-paths'
import eslint from 'vite-plugin-eslint';


export default defineConfig({
// depending on your application, base can also be "/"
base: '',
plugins: [react(), viteTsconfigPaths()],
plugins: [react(), viteTsconfigPaths(), eslint()],
server: {
// this ensures that the browser opens upon server start
open: true,
Expand Down

0 comments on commit 95a3820

Please sign in to comment.