From c16071afc5320677bc2c13fa4dff941152e18970 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Mon, 22 Feb 2016 11:09:35 -0500 Subject: Move post_body profile change listener into posts view --- web/react/components/channel_header.jsx | 4 ++-- web/react/components/post.jsx | 10 ++++++++-- web/react/components/post_body.jsx | 18 ++---------------- web/react/components/posts_view.jsx | 17 ++++++++++++++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/web/react/components/channel_header.jsx b/web/react/components/channel_header.jsx index 3d0246a96..79f4b1c05 100644 --- a/web/react/components/channel_header.jsx +++ b/web/react/components/channel_header.jsx @@ -147,8 +147,8 @@ export default class ChannelHeader extends React.Component { ); let channelTitle = channel.display_name; - const currentId = this.prop.user.id; - const isAdmin = Utils.isAdmin(this.state.memberChannel.roles) || Utils.isAdmin(this.state.memberTeam.roles); + const currentId = this.props.user.id; + const isAdmin = Utils.isAdmin(this.state.memberChannel.roles) || Utils.isAdmin(this.props.user.roles); const isDirect = (this.state.channel.type === 'D'); if (isDirect) { diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index 3619a9f8f..5a850d1c5 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -99,6 +99,10 @@ export default class Post extends React.Component { return true; } + if (nextProps.hasProfiles !== this.props.hasProfiles) { + return true; + } + return false; } getCommentCount(props) { @@ -223,6 +227,7 @@ export default class Post extends React.Component { posts={posts} handleCommentClick={this.handleCommentClick} retryPost={this.retryPost} + hasProfiles={this.props.hasProfiles} /> @@ -233,7 +238,7 @@ export default class Post extends React.Component { } Post.propTypes = { - post: React.PropTypes.object, + post: React.PropTypes.object.isRequired, posts: React.PropTypes.object, parentPost: React.PropTypes.object, sameUser: React.PropTypes.bool, @@ -241,5 +246,6 @@ Post.propTypes = { hideProfilePic: React.PropTypes.bool, isLastComment: React.PropTypes.bool, shouldHighlight: React.PropTypes.bool, - displayNameType: React.PropTypes.string + displayNameType: React.PropTypes.string, + hasProfiles: React.PropTypes.bool }; diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index d71ac6ec7..efeabdfff 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -33,7 +33,6 @@ class PostBody extends React.Component { this.isImgLoading = false; - this.handleUserChange = this.handleUserChange.bind(this); this.parseEmojis = this.parseEmojis.bind(this); this.createEmbed = this.createEmbed.bind(this); this.createImageEmbed = this.createImageEmbed.bind(this); @@ -80,26 +79,12 @@ class PostBody extends React.Component { componentDidMount() { this.parseEmojis(); - - UserStore.addChangeListener(this.handleUserChange); } componentDidUpdate() { this.parseEmojis(); } - componentWillUnmount() { - UserStore.removeChangeListener(this.handleUserChange); - } - - handleUserChange() { - if (!this.state.hasProfiles) { - const profiles = UserStore.getProfiles(); - - this.setState({hasProfiles: profiles && Object.keys(profiles).length > 1}); - } - } - componentWillReceiveProps(nextProps) { const linkData = Utils.extractLinks(nextProps.post.message); if (this.props.post.filenames.length === 0 && this.state.links && this.state.links.length > 0) { @@ -357,7 +342,8 @@ PostBody.propTypes = { post: React.PropTypes.object.isRequired, parentPost: React.PropTypes.object, retryPost: React.PropTypes.func.isRequired, - handleCommentClick: React.PropTypes.func.isRequired + handleCommentClick: React.PropTypes.func.isRequired, + hasProfiles: React.PropTypes.bool }; export default injectIntl(PostBody); diff --git a/web/react/components/posts_view.jsx b/web/react/components/posts_view.jsx index 15810d9cf..2d79b7d00 100644 --- a/web/react/components/posts_view.jsx +++ b/web/react/components/posts_view.jsx @@ -28,6 +28,7 @@ export default class PostsView extends React.Component { this.handleResize = this.handleResize.bind(this); this.scrollToBottom = this.scrollToBottom.bind(this); this.scrollToBottomAnimated = this.scrollToBottomAnimated.bind(this); + this.onUserChange = this.onUserChange.bind(this); this.jumpToPostNode = null; this.wasAtBottom = true; @@ -38,7 +39,8 @@ export default class PostsView extends React.Component { this.state = { displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'), isScrolling: false, - topPostId: null + topPostId: null, + hasProfiles: false }; } static get SCROLL_TYPE_FREE() { @@ -242,6 +244,7 @@ export default class PostsView extends React.Component { shouldHighlight={shouldHighlight} onClick={() => EventHelpers.emitPostFocusEvent(post.id)} //eslint-disable-line no-loop-func displayNameType={this.state.displayNameType} + hasProfiles={this.state.hasProfiles} /> ); @@ -367,9 +370,11 @@ export default class PostsView extends React.Component { if (this.props.postList != null) { this.updateScrolling(); } + UserStore.addChangeListener(this.onUserChange); window.addEventListener('resize', this.handleResize); } componentWillUnmount() { + UserStore.removeChangeListener(this.onUserChange); window.removeEventListener('resize', this.handleResize); } componentDidUpdate() { @@ -413,9 +418,19 @@ export default class PostsView extends React.Component { if (this.state.isScrolling !== nextState.isScrolling) { return true; } + if (this.state.hasProfiles !== nextState.hasProfiles) { + return true; + } return false; } + onUserChange() { + if (!this.state.hasProfiles) { + const profiles = UserStore.getProfiles(); + + this.setState({hasProfiles: profiles && Object.keys(profiles).length > 1}); + } + } render() { let posts = []; let order = []; -- cgit v1.2.3-1-g7c22