AllenYuan

pagination - onSetpage for ProfileFavorites

Apr 19th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ...
  2.  
  3. const mapDispatchToProps = dispatch => ({
  4.   onFollow: username => dispatch({
  5.     type: 'FOLLOW_USER',
  6.     payload: agent.Profile.follow(username)
  7.   }),
  8.   onLoad: (payload) =>
  9.     dispatch({ type: 'PROFILE_FAVORITES_PAGE_LOADED', payload }),
  10.   onSetPage: (page, payload) => dispatch({ type: 'SET_PAGE', page, payload }),
  11.   onUnfollow: username => dispatch({
  12.     type: 'UNFOLLOW_USER',
  13.     payload: agent.Profile.unfollow(username)
  14.   }),
  15.   onUnload: () =>
  16.     dispatch({ type: 'PROFILE_FAVORITES_PAGE_UNLOADED' })
  17. });
  18.  
  19. class ProfileFavorites extends Profile {
  20.   // ...
  21.   // override onSetPage from Profile: this version provides the favorited articles data.
  22.   onSetPage(page) {
  23.     const promise =
  24.       agent.Articles.favoritedBy(this.props.profile.username, page);
  25.     this.props.onSetPage(page, promise);
  26.   }
  27.  
  28.   // ...
  29. }
  30.  
  31. export default connect(mapStateToProps, mapDispatchToProps)(ProfileFavorites);
Advertisement
Add Comment
Please, Sign In to add comment