import React, { useState } from 'react'; import { AppBar, Toolbar, Typography, List, ListItem, ListItemText, ListItemIcon, Divider, Grid, Paper, Drawer, makeStyles, useMediaQuery, IconButton } from '@material-ui/core'; import { useTheme } from "@material-ui/core/styles"; import MenuIcon from '@material-ui/icons/Menu'; import TimelineIcon from '@material-ui/icons/Timeline'; import PauseCircleFilledIcon from '@material-ui/icons/PauseCircleFilled'; import PlayCircleFilledIcon from '@material-ui/icons/PlayCircleFilled'; import NotificationsActiveIcon from '@material-ui/icons/NotificationsActive'; import FormatListBulletedIcon from '@material-ui/icons/FormatListBulleted'; import TrendingUpIcon from '@material-ui/icons/TrendingUp'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import { useHistory } from 'react-router-dom'; import t from '../common/localization'; const useStyles = makeStyles(theme => ({ root: { height: '100%', display: 'flex', }, content: { flex: 1, overflow: 'auto', padding: theme.spacing(2), }, drawer: { width: 360, [theme.breakpoints.down("md")]: { width: 320, } }, drawerHeader: { ...theme.mixins.toolbar, display: 'flex', alignItems: 'center', padding: theme.spacing(0, 1), }, form: { padding: theme.spacing(1, 2, 2), }, })); const ReportLayoutPage = ({ children, filter }) => { const classes = useStyles(); const history = useHistory(); const theme = useTheme(); const matchesMD = useMediaQuery(theme.breakpoints.down("md")); const [openDrawer, setOpenDrawer] = useState(false); const [value, setValue] = useState(0); const routes = [ { name: t('reportRoute'), link: '/reports/route', icon: , activeIndex: 0 }, { name: t('reportEvents'), link: '/reports/event', icon: , activeIndex: 1 }, { name: t('reportTrips'), link: '/reports/trip', icon: , activeIndex: 2 }, { name: t('reportStops'), link: '/reports/stop', icon: , activeIndex: 3 }, { name: t('reportSummary'), link: '/reports/summary', icon: , activeIndex: 4 }, { name: t('reportChart'), link: '/reports/chart', icon: , activeIndex: 5 }, ]; const handleClick = (route) => { history.push(route.link); } console.log('rendering Layout, ', value); return (
{matchesMD && setOpenDrawer(!openDrawer)} className={classes.menuButton} > Reports } setOpenDrawer(!openDrawer)} classes={{ paper: classes.drawer }} > { !matchesMD && <>
Reports
} {routes.map(route => ( { setValue(route.activeIndex); handleClick(route)}} > {route.icon} ))}
); } export default ReportLayoutPage;