From 1f049af2b7ea41a5e1e79a8263e10fa58f186c8d Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Tue, 23 Feb 2016 11:09:59 -0500 Subject: Refactor listener out of user profile and fix thread logic --- web/react/components/user_profile.jsx | 45 ++++++----------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) (limited to 'web/react/components/user_profile.jsx') diff --git a/web/react/components/user_profile.jsx b/web/react/components/user_profile.jsx index 1e393cfe9..31b2b9907 100644 --- a/web/react/components/user_profile.jsx +++ b/web/react/components/user_profile.jsx @@ -2,7 +2,6 @@ // See License.txt for license information. import * as Utils from '../utils/utils.jsx'; -import UserStore from '../stores/user_store.jsx'; import {FormattedMessage} from 'mm-intl'; @@ -19,45 +18,15 @@ function nextId() { export default class UserProfile extends React.Component { constructor(props) { super(props); - this.uniqueId = nextId(); - this.onChange = this.onChange.bind(this); - - this.state = this.getStateFromStores(this.props.userId); - } - getStateFromStores(userId) { - var profile = UserStore.getProfile(userId); - - if (profile == null) { - return {profile: {id: '0', username: '...'}}; - } - - return {profile}; } componentDidMount() { - UserStore.addChangeListener(this.onChange); if (!this.props.disablePopover) { $('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'}); } } - componentWillUnmount() { - UserStore.removeChangeListener(this.onChange); - } - onChange(userId) { - if (!userId || userId === this.props.userId) { - var newState = this.getStateFromStores(this.props.userId); - if (!Utils.areObjectsEqual(newState, this.state)) { - this.setState(newState); - } - } - } - componentWillReceiveProps(nextProps) { - if (this.props.userId !== nextProps.userId) { - this.setState(this.getStateFromStores(nextProps.userId)); - } - } render() { - var name = Utils.displayUsername(this.state.profile.id); + var name = Utils.displayUsername(this.props.user.id); if (this.props.overwriteName) { name = this.props.overwriteName; } else if (!name) { @@ -68,7 +37,7 @@ export default class UserProfile extends React.Component { return
{name}
; } - var profileImg = '/api/v1/users/' + this.state.profile.id + '/image?time=' + this.state.profile.update_at + '&' + Utils.getSessionIndex(); + var profileImg = '/api/v1/users/' + this.props.user.id + '/image?time=' + this.props.user.update_at + '&' + Utils.getSessionIndex(); if (this.props.overwriteImage) { profileImg = this.props.overwriteImage; } @@ -100,14 +69,14 @@ export default class UserProfile extends React.Component { dataContent.push(
- {this.state.profile.email} + {this.props.user.email}
); @@ -139,13 +108,13 @@ export default class UserProfile extends React.Component { } UserProfile.defaultProps = { - userId: '', + user: {}, overwriteName: '', overwriteImage: '', disablePopover: false }; UserProfile.propTypes = { - userId: React.PropTypes.string, + user: React.PropTypes.object.isRequired, overwriteName: React.PropTypes.string, overwriteImage: React.PropTypes.string, disablePopover: React.PropTypes.bool -- cgit v1.2.3-1-g7c22