AllenYuan

Untitled

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