Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. import React, { Component } from 'react';
  2. import { Redirect, Route, Switch } from 'react-router';
  3. import AppRouting from './AppRouting';
  4. import { PROJECT_NAME } from './constants/Env';
  5. import { SnackbarProvider } from 'notistack';
  6. import { create } from 'jss';
  7. import { CssBaseline, IconButton, MuiThemeProvider, createMuiTheme } from '@material-ui/core';
  8. import { StylesProvider, jssPreset } from '@material-ui/styles';
  9. import { blueGrey, indigo, orange, red, green } from '@material-ui/core/colors';
  10. import CloseIcon from '@material-ui/icons/Close';
  11. // Our theme
  12. const theme = createMuiTheme({
  13. palette: {
  14. primary: indigo,
  15. secondary: blueGrey,
  16. highlight_idle: blueGrey[900],
  17. highlight_warn: orange[500],
  18. highlight_error: red[500],
  19. highlight_success: green[500],
  20. },
  21. });
  22. // JSS instance
  23. const jss = create(jssPreset());
  24. // this redirect forces a call to authenticationContext.refresh() which invalidates the JWT if it is invalid.
  25. const unauthorizedRedirect = () => <Redirect to="/" />;
  26. class App extends Component {
  27. notistackRef = React.createRef();
  28. componentDidMount() {
  29. document.title = PROJECT_NAME;
  30. }
  31. onClickDismiss = (key) => () => {
  32. this.notistackRef.current.closeSnackbar(key);
  33. }
  34. render() {
  35. return (
  36. <StylesProvider jss={jss}>
  37. <MuiThemeProvider theme={theme}>
  38. <SnackbarProvider maxSnack={3} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
  39. ref={this.notistackRef}
  40. action={(key) => (
  41. <IconButton onClick={this.onClickDismiss(key)} size="small">
  42. <CloseIcon />
  43. </IconButton>
  44. )}>
  45. <CssBaseline />
  46. <Switch>
  47. <Route exact path="/unauthorized" component={unauthorizedRedirect} />
  48. <Route component={AppRouting} />
  49. </Switch>
  50. </SnackbarProvider>
  51. </MuiThemeProvider>
  52. </StylesProvider>
  53. );
  54. }
  55. }
  56. export default App