Skip to content

Commit

Permalink
follow live update working (whew)
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-4 committed Jan 12, 2018
1 parent d29c050 commit 8a5eb97
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
12 changes: 12 additions & 0 deletions client/src/components/prof_pg/ProfilePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ class ProfilePanel extends React.Component {
fetch('/follow', postConfig);
this.props.followUser();

let {description, name, prof_pic, user_id} = this.props.loggedInUser;
var loggedInFollowerObj = {
description: description,
name: name,
prof_pic: prof_pic,
user_id: user_id
};

bodyObj.status === 'addFollow'
? this.props.changeFollowersLive(loggedInFollowerObj, 'add')
: this.props.changeFollowersLive(loggedInFollowerObj, 'rm');

}

render() {
Expand Down
7 changes: 6 additions & 1 deletion client/src/components/prof_pg/UserProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class UserProfile extends React.Component {
render() {
return (
<div>
<ProfilePanel user={this.props.user} followUser={e => this.followUser(e)} loggedInUser={this.props.loggedInUser} isFollowed={this.state.following} />
<ProfilePanel user={this.props.user}
followUser={e => this.followUser(e)}
loggedInUser={this.props.loggedInUser}
isFollowed={this.state.following}
changeFollowersLive={this.props.changeFollowersLive}
/>
<PictureGrid user={this.props.user} loggedInUser={this.props.loggedInUser} />
</div>
);
Expand Down
18 changes: 17 additions & 1 deletion client/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class App extends React.Component {
.catch(err => console.log('error fetching allprofiles'));
}

changeFollowersLive (followerObj, addOrRm) {
var user = this.state.onPageForUser;

if (addOrRm === 'add') {
user.followers.push(followerObj);
this.setState({onPageForUser: user});
} else {
user.followers = user.followers.filter(follower => followerObj.user_id !== follower.user_id);
this.setState({onPageForUser: user});
}

}

changeUser(userId) {
this.mountUser(userId, 'change');
}
Expand Down Expand Up @@ -86,7 +99,10 @@ class App extends React.Component {
<div>
<NavBar allUsers={this.state.allUsernames} changeUser={e => this.changeUser(e)} changePage={e => this.changePage(e)}/> {/* Albert */}
{this.state.onPageForUser &&
<UserProfile loggedInUser={this.state.loggedInUser} user={this.state.onPageForUser} />
<UserProfile
loggedInUser={this.state.loggedInUser}
user={this.state.onPageForUser}
changeFollowersLive = {this.changeFollowersLive.bind(this)} />
}
</div>
);
Expand Down

0 comments on commit 8a5eb97

Please sign in to comment.