-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-5035 Added loading of missing profiles when hovering over reactio…
…ns (#5887)
- Loading branch information
Showing
8 changed files
with
122 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
webapp/components/post_view/components/reaction_container.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import React from 'react'; | ||
|
||
import {addReaction, removeReaction} from 'actions/post_actions.jsx'; | ||
import * as UserActions from 'actions/user_actions.jsx'; | ||
|
||
import UserStore from 'stores/user_store.jsx'; | ||
|
||
import Reaction from './reaction.jsx'; | ||
|
||
export default class ReactionContainer extends React.Component { | ||
static propTypes = { | ||
post: React.PropTypes.object.isRequired, | ||
emojiName: React.PropTypes.string.isRequired, | ||
reactions: React.PropTypes.arrayOf(React.PropTypes.object), | ||
emojis: React.PropTypes.object.isRequired | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.handleUsersChanged = this.handleUsersChanged.bind(this); | ||
|
||
this.getStateFromStore = this.getStateFromStore.bind(this); | ||
|
||
this.getProfilesForReactions = this.getProfilesForReactions.bind(this); | ||
this.getMissingProfiles = this.getMissingProfiles.bind(this); | ||
|
||
this.state = this.getStateFromStore(props); | ||
} | ||
|
||
componentDidMount() { | ||
UserStore.addChangeListener(this.handleUsersChanged); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.reactions !== this.props.reactions) { | ||
this.setState(this.getStateFromStore(nextProps)); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
UserStore.removeChangeListener(this.handleUsersChanged); | ||
} | ||
|
||
handleUsersChanged() { | ||
this.setState(this.getStateFromStore()); | ||
} | ||
|
||
getStateFromStore(props = this.props) { | ||
const profiles = this.getProfilesForReactions(props.reactions); | ||
const otherUsers = props.reactions.length - profiles.length; | ||
|
||
return { | ||
profiles, | ||
otherUsers, | ||
currentUserId: UserStore.getCurrentId() | ||
}; | ||
} | ||
|
||
getProfilesForReactions(reactions) { | ||
return reactions.map((reaction) => { | ||
return UserStore.getProfile(reaction.user_id); | ||
}).filter((profile) => Boolean(profile)); | ||
} | ||
|
||
getMissingProfiles() { | ||
const ids = this.props.reactions.map((reaction) => reaction.user_id); | ||
|
||
UserActions.getMissingProfiles(ids); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Reaction | ||
{...this.props} | ||
{...this.state} | ||
actions={{ | ||
addReaction, | ||
getMissingProfiles: this.getMissingProfiles, | ||
removeReaction | ||
}} | ||
/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters