AllenYuan

Untitled

Jun 1st, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // npm packages
  2. import darkBaseTheme from 'material-ui/styles/baseThemes/darkBaseTheme';
  3. import getMuiTheme from 'material-ui/styles/getMuiTheme';
  4. import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
  5. import React from 'react';
  6. import { Helmet } from 'react-helmet';
  7. import { connect } from 'react-redux';
  8. import { Route,Switch, withRouter } from 'react-router-dom';
  9. import styled from 'styled-components';
  10.  
  11. // sibling files
  12. import constants from '../constants';
  13. import Home from '../Home';
  14. import Header from '../Header';
  15. import FourOhFour from '../FourOhFour';
  16.  
  17. // helpers
  18. import GlobalStyle from './GlobalStyle';
  19. import muiTheme from './muiTheme';
  20.  
  21. // global app styling
  22. const StyledDiv = styled.div`
  23. transition: ${constants.normalTransition};
  24. position: relative;
  25. display: flex;
  26. flex-direction: column;
  27. height: 100%;
  28. // add space for left panel
  29. left: ${(props) => (props.open ? '256px' : '0px')};
  30. margin-top: 0px;
  31. // display background image on homepage
  32. background-image: ${(props) =>
  33. props.location.pathname === '/'
  34. ? 'url("assets/images/home-background.png")'
  35. : ''};
  36. background-position: center top -56px;
  37. background-repeat: ${(props) =>
  38. props.location.pathname === '/' ? 'no-repeat' : ''};
  39. `;
  40.  
  41. // global body styling
  42. const StyledBodyDiv = styled.div`
  43. padding: 25px;
  44. flex-grow: 1;
  45.  
  46. // at the min width, expand the body to the whole page
  47. @media only screen and (min-width: ${constants.appWidth}px) {
  48. width: ${constants.appWidth}px;
  49. margin: auto;
  50. }
  51. `;
  52.  
  53. const App = (props) => {
  54. console.log('app props', props);
  55. const { strings, location } = props;
  56.  
  57. return (
  58. <MuiThemeProvider muiTheme = {getMuiTheme(darkBaseTheme, muiTheme)}>
  59. <GlobalStyle />
  60. <StyledDiv {...props}>
  61. <Helmet
  62. defaultTitle = {strings.title_default}
  63. titleTemplate = {strings.title_template}
  64. />
  65. <Header location={location} />
  66. <StyledBodyDiv {...props}>
  67. {/* routing */}
  68. <Switch>
  69. <Route exact path = "/" component = {Home} />
  70. <Route component={FourOhFour} />
  71. </Switch>
  72. </StyledBodyDiv>
  73. </StyledDiv>
  74. </MuiThemeProvider>
  75. )
  76. }
  77.  
  78. const mapStateToProps = (state) => ({
  79. strings: state.app.strings,
  80. });
  81.  
  82. export default connect(mapStateToProps)(withRouter(App));
Advertisement
Add Comment
Please, Sign In to add comment