AllenYuan

pagination - onSetPage for MainView

Apr 19th, 2020
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ...
  2.  
  3. const mapDispatchToProps = dispatch => ({
  4.   // dispatch SET_PAGE action with page p and promise for 10p articles from the specified api
  5.   onSetPage: (tab, p) => dispatch({
  6.     type: 'SET_PAGE',
  7.     page: p,
  8.     payload: tab === 'feed' ? agent.Articles.feed(p) : agent.Articles.all(p)
  9.   }),
  10.   onTabClick: (tab, payload) => dispatch({ type: 'CHANGE_TAB', tab, payload })
  11. });
  12.  
  13. const MainView = props => {
  14.   const onSetPage = page => props.onSetPage(props.tab, page);
  15.   return (
  16.     <div className="col-md-9">
  17.       <div className="feed-toggle">
  18.         <ul className="nav nav-pills outline-active">
  19.  
  20.           <YourFeedTab
  21.             token={props.token}
  22.             tab={props.tab}
  23.             onTabClick={props.onTabClick} />
  24.  
  25.           <GlobalFeedTab tab={props.tab} onTabClick={props.onTabClick} />
  26.  
  27.           <TagFilterTab tag={props.tag} />
  28.  
  29.         </ul>
  30.       </div>
  31.       // pass onSetPage to ArticleList
  32.       <ArticleList
  33.         articles={props.articles}
  34.         articlesCount={props.articlesCount}
  35.         currentPage={props.currentPage}
  36.         onSetPage={onSetPage} />
  37.     </div>
  38.   );
  39. };
  40.  
  41. export default connect(mapStateToProps, mapDispatchToProps)(MainView);
Advertisement
Add Comment
Please, Sign In to add comment