From 04e364f4f7f9e132c9929f44851a5608a5c0bf21 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 5 Jul 2017 16:28:32 -0400 Subject: Do not scroll center channel to bottom when posting in RHS (#6852) --- webapp/actions/global_actions.jsx | 5 +++-- webapp/components/create_post.jsx | 3 ++- webapp/components/post_view/post_list.jsx | 23 +++++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'webapp') diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index 2ab2692c0..33a1c8432 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -551,8 +551,9 @@ export function redirectUserToDefaultTeam() { } } -export function postListScrollChange() { +export function postListScrollChange(forceScrollToBottom = false) { AppDispatcher.handleViewAction({ - type: EventTypes.POST_LIST_SCROLL_CHANGE + type: EventTypes.POST_LIST_SCROLL_CHANGE, + value: forceScrollToBottom }); } diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx index 56f392292..4a2cf5302 100644 --- a/webapp/components/create_post.jsx +++ b/webapp/components/create_post.jsx @@ -261,7 +261,8 @@ export default class CreatePost extends React.Component { }); } - PostActions.createPost(post, this.state.fileInfos, null, + PostActions.createPost(post, this.state.fileInfos, + () => GlobalActions.postListScrollChange(true), (err) => { if (err.id === 'api.post.create_post.root_id.app_error') { // this should never actually happen since you can't reply from this textbox diff --git a/webapp/components/post_view/post_list.jsx b/webapp/components/post_view/post_list.jsx index a0aed8152..13cc28da3 100644 --- a/webapp/components/post_view/post_list.jsx +++ b/webapp/components/post_view/post_list.jsx @@ -117,12 +117,12 @@ export default class PostList extends React.PureComponent { this.loadPosts(this.props.channel.id, this.props.focusedPostId); GlobalEventEmitter.addListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize); - window.addEventListener('resize', this.handleResize); + window.addEventListener('resize', () => this.handleResize()); } componentWillUnmount() { GlobalEventEmitter.removeListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize); - window.removeEventListener('resize', this.handleResize); + window.removeEventListener('resize', () => this.handleResize()); } componentWillReceiveProps(nextProps) { @@ -210,20 +210,18 @@ export default class PostList extends React.PureComponent { } if (postList && prevPosts && posts && posts[0] && prevPosts[0]) { - // A new message was posted, so scroll to bottom if it was from current user - // or if user was already scrolled close to bottom + // A new message was posted, so scroll to bottom if user + // was already scrolled close to bottom let doScrollToBottom = false; - if (posts[0].id !== prevPosts[0].id && posts[0].pending_post_id !== prevPosts[0].pending_post_id) { + const postId = posts[0].id; + const prevPostId = prevPosts[0].id; + const pendingPostId = posts[0].pending_post_id; + if (postId !== prevPostId && pendingPostId !== prevPostId) { // If already scrolled to bottom if (this.wasAtBottom()) { doScrollToBottom = true; } - // If new post was by current user - if (posts[0].user_id === this.props.currentUserId) { - doScrollToBottom = true; - } - // If new post was ephemeral if (Utils.isPostEphemeral(posts[0])) { doScrollToBottom = true; @@ -252,10 +250,11 @@ export default class PostList extends React.PureComponent { return this.previousClientHeight + this.previousScrollTop >= this.previousScrollHeight - CLOSE_TO_BOTTOM_SCROLL_MARGIN; } - handleResize = () => { + handleResize = (forceScrollToBottom) => { const postList = this.refs.postlist; + const doScrollToBottom = this.wasAtBottom() || forceScrollToBottom; - if (postList && this.wasAtBottom()) { + if (postList && doScrollToBottom) { postList.scrollTop = postList.scrollHeight; this.previousScrollHeight = postList.scrollHeight; -- cgit v1.2.3-1-g7c22