Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4.  
  5. // Import Components
  6. import Helmet from 'react-helmet';
  7. import Header from './components/Header/Header';
  8. import Footer from './components/Footer/Footer';
  9.  
  10. // Import Actions
  11. import { toggleAddPost } from './AppActions';
  12. import { logout } from '../Auth/AuthActions';
  13. import { clearCurrentProfile } from '../Profile/ProfileActions';
  14.  
  15. export class App extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = { isMounted: false };
  19. }
  20.  
  21. componentDidMount() {
  22. this.setState({isMounted: true}); // eslint-disable-line
  23. }
  24.  
  25. handleLogout = () => {
  26. this.props.dispatch(clearCurrentProfile());
  27. this.props.dispatch(logout(this.props.router));
  28. };
  29.  
  30. toggleAddPostSection = () => {
  31. this.props.dispatch(toggleAddPost());
  32. };
  33.  
  34. render() {
  35. return (
  36. <div>
  37. <Helmet
  38. title="Group Travel"
  39. titleTemplate="%s - Blog App"
  40. meta={[
  41. { charset: 'utf-8' },
  42. {
  43. 'http-equiv': 'X-UA-Compatible',
  44. content: 'IE=edge',
  45. },
  46. {
  47. name: 'viewport',
  48. content: 'width=device-width, initial-scale=1',
  49. },
  50. ]}
  51. />
  52. <Header
  53. toggleAddPost={this.toggleAddPostSection}
  54. logout={this.handleLogout}
  55. isAuthenticated={this.props.isAuthenticated}
  56. userName={this.props.userName}
  57. showEditProfile={this.props.showEditProfile}
  58. />
  59. <br />
  60. <div style={{marginTop:'35px', marginBottom:'35px'}}>
  61. {this.props.children}
  62. </div>
  63. <br />
  64. <Footer />
  65. </div>
  66. );
  67. }
  68. }
  69.  
  70. App.propTypes = {
  71. children: PropTypes.object.isRequired,
  72. dispatch: PropTypes.func.isRequired,
  73. isAuthenticated: PropTypes.bool,
  74. showEditProfile: PropTypes.bool,
  75. userName: PropTypes.string,
  76. router: PropTypes.object,
  77. };
  78.  
  79. const mapStateToProps = state => ({
  80. isAuthenticated: state.auth.isAuthenticated,
  81. userName: state.auth.user.name,
  82. showEditProfile: state.profile.profile !== null && Object.keys(state.profile.profile).length > 0,
  83. });
  84.  
  85. export default connect(mapStateToProps)(App);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement