AllenYuan

http - home integration

Apr 23rd, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // child components
  2. import Banner from './Banner';
  3. import MainView from './MainView';
  4.  
  5. // modules for a redux-connected react component
  6. import React from 'react';
  7. import {connect} from 'react-redux';
  8.  
  9. // our http client
  10. import agent from '../../agent';
  11.  
  12. // extract appName from state
  13. const mapStateToProps = (state) => ({
  14.   appName: state.appName,
  15. });
  16.  
  17. // put action creators in props
  18. const mapDispatchToProps = dispatch => ({
  19.   // dispatch HOME_PAGE_LOADED with promise for articlelist
  20.   onLoad: payload =>
  21.     dispatch({ type: 'HOME_PAGE_LOADED', payload }),
  22. });
  23.  
  24. class Home extends React.Component {
  25.   // on mount, dispatch HOME_PAGE_LOADED with promise for all articles
  26.   componentWillMount() {
  27.     this.props.onLoad(agent.Articles.all());
  28.   }
  29.  
  30.   render() {
  31.     // render a Banner followed by a MainView with a 'Popular Tags' sidebar
  32.     return (
  33.       <div className="home-page">
  34.         <Banner appName={this.props.appName} />
  35.         <div className="container page">
  36.           <div className="row">
  37.             <MainView />
  38.             <div className="col-md-3">
  39.               <div className="sidebar">
  40.                 <p>Popular Tags</p>
  41.               </div>
  42.             </div>
  43.           </div>
  44.         </div>
  45.       </div>
  46.     );
  47.   }
  48. }
  49.  
  50. // connect Home to redux and export it
  51. export default connect(mapStateToProps, mapDispatchToProps)(Home);
Advertisement
Add Comment
Please, Sign In to add comment