Skip to content

Commit

Permalink
Frontend app page without target styles (#23)
Browse files Browse the repository at this point in the history
* Add css

* Add sidebar

* Format

* Add AppBar

* Add AppMain

* delete non-used import

* delete non-used code lines
  • Loading branch information
PiotrRynio authored Apr 24, 2021
1 parent 1352dae commit 2aebc7c
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 27 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/atoms/constants/sizes.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const MIN_CARD_COMPONENT_WIDTH : string = "300px";
export const MIN_CARD_COMPONENT_WIDTH : string = "300px";
export const DRAWER_WIDTH = 240;
11 changes: 11 additions & 0 deletions frontend/src/components/atoms/hooks/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createContext } from 'react';

export const defaultObject = {
isOpenDrawer: false,
handleDrawerOpen: () => {
},
handleDrawerClose: () => {
},
};

export const AppContext = createContext(defaultObject);
70 changes: 70 additions & 0 deletions frontend/src/components/organisms/AppBar/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Badge, makeStyles, Typography } from '@material-ui/core';
import clsx from 'clsx';
import IconButton from '@material-ui/core/IconButton';
import React, { useContext } from 'react';
import { AppContext } from '../../atoms/hooks/AppContext';
import { DRAWER_WIDTH } from '../../atoms/constants/sizes';
import Toolbar from '@material-ui/core/Toolbar';
import MenuIcon from '@material-ui/icons/Menu';
import NotificationsIcon from '@material-ui/icons/Notifications';
import { AppBar as AppBarFromSigma } from '@material-ui/core';

export function AppBar() {
const classes = useStyles();
const { handleDrawerOpen } = useContext(AppContext);
const { isOpenDrawer } = useContext(AppContext);

return (
<AppBarFromSigma position='absolute' className={clsx(classes.appBar, isOpenDrawer && classes.appBarShift)}>
<Toolbar className={classes.toolbar}>
<IconButton
edge='start'
color='inherit'
aria-label='open drawer'
onClick={handleDrawerOpen}
className={clsx(classes.menuButton, isOpenDrawer && classes.menuButtonHidden)}
>
<MenuIcon />
</IconButton>
<Typography component='h1' variant='h6' color='inherit' noWrap className={classes.title}>
Dashboard
</Typography>
<IconButton color='inherit'>
<Badge badgeContent={4} color='secondary'>
<NotificationsIcon />
</Badge>
</IconButton>
</Toolbar>
</AppBarFromSigma>
);
}

const useStyles = makeStyles((theme) => ({
toolbar: {
paddingRight: 24, // keep right padding when drawer closed
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
appBarShift: {
marginLeft: DRAWER_WIDTH,
width: `calc(100% - ${DRAWER_WIDTH}px)`,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
menuButton: {
marginRight: 36,
},
menuButtonHidden: {
display: 'none',
},
title: {
flexGrow: 1,
},
}));
41 changes: 41 additions & 0 deletions frontend/src/components/organisms/AppMain/AppMain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { makeStyles, Typography } from '@material-ui/core';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { PATH_FOR_MAIN_VIEW } from '../../atoms/constants/routerPaths';
import ClickButton from '../../atoms/Button/ClickButton';

const onClick = () => {
};

export function AppMain() {
const classes = useStyles();

return (
<main className={classes.content}>
<Router>

<Switch>

<Route path={PATH_FOR_MAIN_VIEW} exact>

<Typography variant='h2'>Responsive h3</Typography>

<ClickButton text={'ZADAJ PYTANIE'} onClick={() => onClick()} />

</Route>

</Switch>

</Router>

</main>
);
}

const useStyles = makeStyles((theme) => ({
content: {
overflow: 'auto',
position: 'relative',
flexGrow: 1,
height: '100vh',
},
}));
61 changes: 61 additions & 0 deletions frontend/src/components/organisms/AppSidebar/AppSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Divider, Drawer, makeStyles } from '@material-ui/core';
import clsx from 'clsx';
import IconButton from '@material-ui/core/IconButton';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import React, { useContext } from 'react';
import { AppContext } from '../../atoms/hooks/AppContext';
import { DRAWER_WIDTH } from '../../atoms/constants/sizes';

export function AppSidebar() {
const classes = useStyles();
const { handleDrawerClose } = useContext(AppContext);
const { isOpenDrawer } = useContext(AppContext);

return (
<Drawer
variant='permanent'
classes={{
paper: clsx(classes.drawerPaper, !isOpenDrawer && classes.drawerPaperClose),
}}
open={isOpenDrawer}
>
<div className={classes.toolbarIcon}>
<IconButton onClick={handleDrawerClose}>
<ChevronLeftIcon />
</IconButton>
</div>
<Divider />
<Divider />
</Drawer>
);
}

const useStyles = makeStyles((theme) => ({
toolbarIcon: {
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
padding: '0 8px',
...theme.mixins.toolbar,
},
drawerPaper: {
position: 'relative',
whiteSpace: 'nowrap',
width: DRAWER_WIDTH,
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
drawerPaperClose: {
overflowX: 'hidden',
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
width: theme.spacing(7),
[theme.breakpoints.up('sm')]: {
width: theme.spacing(9),
},
},
}));
69 changes: 43 additions & 26 deletions frontend/src/components/pages/Integramic/Integramic.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
import React, {useState} from 'react';
import {MuiThemeProvider, Typography} from '@material-ui/core';
import {THEME} from '../../atoms/constants/ThemeMUI';
import ClickButton from '../../atoms/Button/ClickButton';
import UserAvatarAndName from '../../molecules/UserAvatarAndName/UserAvatarAndName';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom';
import {PATH_FOR_MAIN_VIEW} from '../../atoms/constants/routerPaths';
import {LoginPage} from "../LoginPage/LoginPage";
import Logo from "../../atoms/Logo/Logo";

const onClick = () => {
};
import React, { useState } from 'react';
import {
CssBaseline,
makeStyles,
MuiThemeProvider,
} from '@material-ui/core';
import { THEME } from '../../atoms/constants/ThemeMUI';
import { AppSidebar } from '../../organisms/AppSidebar/AppSidebar';
import { AppContext } from '../../atoms/hooks/AppContext';
import { AppBar } from '../../organisms/AppBar/AppBar';
import { AppMain } from '../../organisms/AppMain/AppMain';
import { LoginPage } from '../LoginPage/LoginPage';


export function Integramic() {
const classes = useStyles();
const [isOpenDrawer, setIsOpenDrawer] = useState(true);

const handleDrawerOpen = () => {
setIsOpenDrawer(true);
};
const handleDrawerClose = () => {
setIsOpenDrawer(false);
};

const [state, setState] = useState<AuthState>({authenticatedUser: undefined, isLoading: false});
if (state.authenticatedUser === undefined) {
return <LoginPage onAuthenticated={user => setState({authenticatedUser: user, isLoading: false})} />
}

return (
<MuiThemeProvider theme={THEME}>
<Router>
<Switch>
<Route path={PATH_FOR_MAIN_VIEW} exact>
<Typography variant="h2">Responsive h3</Typography>

<ClickButton text={'ZADAJ PYTANIE'} onClick={() => onClick()} />

<UserAvatarAndName />
<Logo />
</Route>
</Switch>
</Router>
</MuiThemeProvider>
<MuiThemeProvider theme={THEME}>
<div className={classes.root}>
<AppContext.Provider value={{ isOpenDrawer, handleDrawerOpen, handleDrawerClose }}>
<CssBaseline />

<AppBar />

<AppSidebar />
<AppMain />

</AppContext.Provider>
</div>
</MuiThemeProvider>
);
}

const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
},
}));

export type AuthState = {
readonly authenticatedUser: { email: string } | undefined;
readonly isLoading: boolean
Expand Down

0 comments on commit 2aebc7c

Please sign in to comment.