Layout.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import GlobalEffect from './GlobalEffect';
  2. import Header from './Header';
  3. import { makeStyles, Theme, createStyles } from '@material-ui/core';
  4. import NavMenu from '../menu/NavMenu';
  5. import { NavMenuItem } from '../menu/Types';
  6. import { useContext } from 'react';
  7. import icons from '../icons/Icons';
  8. import { useTranslation } from 'react-i18next';
  9. import { useHistory } from 'react-router-dom';
  10. import { authContext } from '../../context/Auth';
  11. const useStyles = makeStyles((theme: Theme) =>
  12. createStyles({
  13. root: {
  14. minHeight: '100vh',
  15. backgroundColor: '#f5f5f5',
  16. },
  17. content: {
  18. display: 'flex',
  19. },
  20. body: {
  21. flex: 1,
  22. display: 'flex',
  23. flexDirection: 'column',
  24. height: '100vh',
  25. overflowY: 'scroll',
  26. },
  27. activeConsole: {
  28. '& path': {
  29. fill: theme.palette.primary.main,
  30. },
  31. },
  32. normalConsole: {
  33. '& path': {
  34. fill: '#82838e',
  35. },
  36. },
  37. })
  38. );
  39. const Layout = (props: any) => {
  40. const history = useHistory();
  41. const { isAuth } = useContext(authContext);
  42. const { t } = useTranslation('nav');
  43. const classes = useStyles();
  44. const menuItems: NavMenuItem[] = [
  45. {
  46. icon: icons.navOverview,
  47. label: t('overview'),
  48. onClick: () => history.push('/'),
  49. },
  50. {
  51. icon: icons.navCollection,
  52. label: t('collection'),
  53. onClick: () => history.push('/collections'),
  54. },
  55. ];
  56. return (
  57. <div className={classes.root}>
  58. <GlobalEffect>
  59. <div className={classes.content}>
  60. {isAuth && (
  61. <NavMenu
  62. width="200px"
  63. data={menuItems}
  64. defaultActive={t('overview')}
  65. // used for nested child menu
  66. defaultOpen={{ [t('overview')]: true }}
  67. />
  68. )}
  69. <div className={classes.body}>
  70. {isAuth && <Header />}
  71. {props.children}
  72. </div>
  73. </div>
  74. </GlobalEffect>
  75. </div>
  76. );
  77. };
  78. export default Layout;