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.

47 lines
1.4 KiB

  1. import React, { Component, RefObject } from 'react';
  2. import { Redirect, Route, Switch } from 'react-router';
  3. import { SnackbarProvider } from 'notistack';
  4. import { IconButton } from '@material-ui/core';
  5. import CloseIcon from '@material-ui/icons/Close';
  6. import AppRouting from './AppRouting';
  7. import CustomMuiTheme from './CustomMuiTheme';
  8. import { PROJECT_NAME } from './api';
  9. // this redirect forces a call to authenticationContext.refresh() which invalidates the JWT if it is invalid.
  10. const unauthorizedRedirect = () => <Redirect to="/" />;
  11. class App extends Component {
  12. notistackRef: RefObject<any> = React.createRef();
  13. componentDidMount() {
  14. document.title = PROJECT_NAME;
  15. }
  16. onClickDismiss = (key: string | number | undefined) => () => {
  17. this.notistackRef.current.closeSnackbar(key);
  18. }
  19. render() {
  20. return (
  21. <CustomMuiTheme>
  22. <SnackbarProvider maxSnack={3} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
  23. ref={this.notistackRef}
  24. action={(key) => (
  25. <IconButton onClick={this.onClickDismiss(key)} size="small">
  26. <CloseIcon />
  27. </IconButton>
  28. )}>
  29. <Switch>
  30. <Route exact path="/unauthorized" component={unauthorizedRedirect} />
  31. <Route component={AppRouting} />
  32. </Switch>
  33. </SnackbarProvider>
  34. </CustomMuiTheme>
  35. );
  36. }
  37. }
  38. export default App