Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- src/components/Profile
- // ...
- const mapDispatchToProps = dispatch => ({
- onFollow: username => dispatch({
- type: 'FOLLOW_USER',
- payload: agent.Profile.follow(username)
- }),
- onLoad: payload => dispatch({ type: 'PROFILE_PAGE_LOADED', payload }),
- // SET_PAGE action with page# and data
- onSetPage: (page, payload) => dispatch({ type: 'SET_PAGE', page, payload }),
- onUnfollow: username => dispatch({
- type: 'UNFOLLOW_USER',
- payload: agent.Profile.unfollow(username)
- }),
- onUnload: () => dispatch({ type: 'PROFILE_PAGE_UNLOADED' })
- });
- class Profile extends React.Component {
- // ...
- // get articles from this author
- onSetPage(page) {
- const promise = agent.Articles.byAuthor(this.props.profile.username, page);
- this.props.onSetPage(page, promise);
- }
- render() {
- const profile = this.props.profile;
- if (!profile) {e
- return null;
- }
- const isUser = this.props.currentUser &&
- this.props.profile.username === this.props.currentUser.username;
- const onSetPage = page => this.onSetPage(page)
- return (
- <div className="profile-page">
- <div className="user-info">
- <div className="container">
- <div className="row">
- <div className="col-xs-12 col-md-10 offset-md-1">
- <img src={profile.image} className="user-img" />
- <h4>{profile.username}</h4>
- <p>{profile.bio}</p>
- <EditProfileSettings isUser={isUser} />
- <FollowUserButton
- isUser={isUser}
- user={profile}
- follow={this.props.onFollow}
- unfollow={this.props.onUnfollow}
- />
- </div>
- </div>
- </div>
- </div>
- <div className="container">
- <div className="row">
- <div className="col-xs-12 col-md-10 offset-md-1">
- <div className="articles-toggle">
- {this.renderTabs()}
- </div>
- // pass onSetPage to ArticleList
- <ArticleList
- articles={this.props.articles}
- articlesCount={this.props.articlesCount}
- currentPage={this.props.currentPage}
- onSetPage={onSetPage} />
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
- export default connect(mapStateToProps, mapDispatchToProps)(Profile);
- export { Profile as Profile, mapStateToProps as mapStateToProps };
Advertisement
Add Comment
Please, Sign In to add comment