Files
bee-dashboard/src/layout/Dashboard.tsx
T
Vojtech Simetka 7fc1356212 ci: added commit lint, build check, test and release (#31)
* ci: added commit lint, build check, test and release

* refactor: fix compilation errors

* ci: add checkout to the tests

* test: resolved issues with running tests

* chore: addressed PR comments

* chore: renamed package-name in release-please
2021-03-31 15:33:09 +02:00

80 lines
2.2 KiB
TypeScript

import React, { useState, useEffect } from 'react'
import { createStyles, Theme, makeStyles } from '@material-ui/core/styles';
import SideBar from '../components/SideBar';
import NavBar from '../components/NavBar';
import { useApiHealth, useDebugApiHealth } from '../hooks/apiHooks';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
toolbar: theme.mixins.toolbar,
content: {
marginLeft: '240px',
marginTop: '64px',
flexGrow: 1,
backgroundColor: theme.palette.background.default,
padding: theme.spacing(3),
paddingBottom:'65px',
},
footer: {
marginLeft: '240px',
backgroundColor: theme.palette.background.default,
position: 'fixed',
bottom: 0,
flexGrow: 1,
width:'-webkit-fill-available',
padding: theme.spacing(2),
textAlign:'center'
},
logo: {
height: '20px',
marginRight: '7px',
}
}),
);
const Dashboard = (props: any) => {
const classes = useStyles();
const [themeMode, toggleThemeMode] = useState('light');
const { health, isLoadingHealth } = useApiHealth()
const { nodeHealth, isLoadingNodeHealth } = useDebugApiHealth()
useEffect(() => {
let theme = localStorage.getItem('theme')
if (theme) {
toggleThemeMode(String(localStorage.getItem('theme')))
} else if (window?.matchMedia('(prefers-color-scheme: dark)')?.matches) {
toggleThemeMode('dark')
}
window?.matchMedia('(prefers-color-scheme: dark)')?.addEventListener('change', e => {
toggleThemeMode(e?.matches ? "dark" : "light")
});
return () => window?.matchMedia('(prefers-color-scheme: dark)')?.removeEventListener('change', e => {
toggleThemeMode(e?.matches ? "dark" : "light")
})
}, [])
let childrenInjectedWithProps = React.cloneElement(props.children, { health, nodeHealth, isLoadingHealth, isLoadingNodeHealth })
return (
<div>
<SideBar {...props} themeMode={themeMode} health={health} nodeHealth={nodeHealth} />
<NavBar themeMode={themeMode} />
<main className={classes.content} >
{childrenInjectedWithProps}
</main>
</div>
)
}
export default Dashboard