AllenYuan

Untitled

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