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/posts_view.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'web/react/components/posts_view.jsx') 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 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/posts_view.jsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'web/react/components/posts_view.jsx') diff --git a/web/react/components/posts_view.jsx b/web/react/components/posts_view.jsx index 2d79b7d00..3a84b51f0 100644 --- a/web/react/components/posts_view.jsx +++ b/web/react/components/posts_view.jsx @@ -28,7 +28,6 @@ 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; @@ -39,8 +38,7 @@ export default class PostsView extends React.Component { this.state = { displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'), isScrolling: false, - topPostId: null, - hasProfiles: false + topPostId: null }; } static get SCROLL_TYPE_FREE() { @@ -147,6 +145,7 @@ export default class PostsView extends React.Component { const postCtls = []; let previousPostDay = new Date(0); const userId = UserStore.getCurrentId(); + const profiles = this.props.profiles; let renderedLastViewed = false; @@ -230,6 +229,13 @@ export default class PostsView extends React.Component { const shouldHighlight = this.props.postsToHighlight && this.props.postsToHighlight.hasOwnProperty(post.id); + let profile; + if (UserStore.getCurrentId() === post.user_id) { + profile = UserStore.getCurrentUser(); + } else { + profile = profiles[post.user_id]; + } + const postCtl = ( EventHelpers.emitPostFocusEvent(post.id)} //eslint-disable-line no-loop-func displayNameType={this.state.displayNameType} - hasProfiles={this.state.hasProfiles} + hasProfiles={profiles && Object.keys(profiles).length > 1} + user={profile} /> ); @@ -370,11 +377,9 @@ 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() { @@ -418,19 +423,12 @@ export default class PostsView extends React.Component { if (this.state.isScrolling !== nextState.isScrolling) { return true; } - if (this.state.hasProfiles !== nextState.hasProfiles) { + if (!Utils.areObjectsEqual(this.props.profiles, nextProps.profiles)) { 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 = []; @@ -528,6 +526,7 @@ PostsView.defaultProps = { PostsView.propTypes = { isActive: React.PropTypes.bool, postList: React.PropTypes.object, + profiles: React.PropTypes.object, scrollPostId: React.PropTypes.string, scrollType: React.PropTypes.number, postViewScrolled: React.PropTypes.func.isRequired, -- cgit v1.2.3-1-g7c22