Layout.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // icon: icons.navConsole,
  57. // label: t('console'),
  58. // onClick: () => history.push('/console'),
  59. // iconActiveClass: classes.activeConsole,
  60. // iconNormalClass: classes.normalConsole,
  61. // },
  62. ];
  63. return (
  64. <div className={classes.root}>
  65. <GlobalEffect>
  66. <div className={classes.content}>
  67. {isAuth && (
  68. <NavMenu
  69. width="200px"
  70. data={menuItems}
  71. defaultActive={t('overview')}
  72. // used for nested child menu
  73. defaultOpen={{ [t('overview')]: true }}
  74. />
  75. )}
  76. <div className={classes.body}>
  77. {isAuth && <Header />}
  78. {props.children}
  79. </div>
  80. </div>
  81. </GlobalEffect>
  82. </div>
  83. );
  84. };
  85. export default Layout;