Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
MM-15080 Use event emitter to scroll to bottom when sending post (mat…
Browse files Browse the repository at this point in the history
  • Loading branch information
hmhealey authored and saturninoabril committed Apr 30, 2019
1 parent ed68b00 commit 2837bb3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
9 changes: 8 additions & 1 deletion actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {batchActions} from 'redux-batched-actions';

import {leaveChannel as leaveChannelRedux, joinChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels';
import * as PostActions from 'mattermost-redux/actions/posts';
import {autocompleteUsers} from 'mattermost-redux/actions/users';
import {Posts} from 'mattermost-redux/constants';
import {getChannel, getChannelByName, getCurrentChannel, getRedirectChannelNameForTeam} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentRelativeTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUserId, getUserByUsername} from 'mattermost-redux/selectors/entities/users';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import {isFavoriteChannel} from 'mattermost-redux/utils/channel_utils';
import {autocompleteUsers} from 'mattermost-redux/actions/users';
import EventEmitter from 'mattermost-redux/utils/event_emitter';

import {openDirectChannelToUserId} from 'actions/channel_actions.jsx';
import {getLastViewedChannelName} from 'selectors/local_storage';
Expand Down Expand Up @@ -202,3 +203,9 @@ export function increasePostVisibility(channelId, beforePostId) {
};
};
}

export function scrollPostListToBottom() {
return () => {
EventEmitter.emit('scroll_post_list_to_bottom');
};
}
3 changes: 3 additions & 0 deletions components/create_post/create_post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ export default class CreatePost extends React.Component {
* Function to get the users timezones in the channel
*/
getChannelTimezones: PropTypes.func.isRequired,

scrollPostListToBottom: PropTypes.func.isRequired,
}).isRequired,
}

Expand Down Expand Up @@ -583,6 +585,7 @@ export default class CreatePost extends React.Component {
post = hookResult.data;

actions.onSubmitPost(post, draft.fileInfos);
actions.scrollPostListToBottom();

this.setState({
submitting: false,
Expand Down
26 changes: 13 additions & 13 deletions components/create_post/create_post.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ const currentUsersLatestPostProp = {id: 'b', root_id: 'a', channel_id: currentCh

const commentCountForPostProp = 10;

function emptyFunction() {} //eslint-disable-line no-empty-function
const actionsProp = {
addMessageIntoHistory: emptyFunction,
moveHistoryIndexBack: emptyFunction,
moveHistoryIndexForward: emptyFunction,
addReaction: emptyFunction,
removeReaction: emptyFunction,
clearDraftUploads: emptyFunction,
onSubmitPost: emptyFunction,
selectPostFromRightHandSideSearchByPostId: emptyFunction,
setDraft: emptyFunction,
setEditingPost: emptyFunction,
openModal: emptyFunction,
addMessageIntoHistory: jest.fn(),
moveHistoryIndexBack: jest.fn(),
moveHistoryIndexForward: jest.fn(),
addReaction: jest.fn(),
removeReaction: jest.fn(),
clearDraftUploads: jest.fn(),
onSubmitPost: jest.fn(),
selectPostFromRightHandSideSearchByPostId: jest.fn(),
setDraft: jest.fn(),
setEditingPost: jest.fn(),
openModal: jest.fn(),
executeCommand: async () => {
return {data: true};
},
getChannelTimezones: emptyFunction,
getChannelTimezones: jest.fn(),
runMessageWillBePostedHooks: async (post) => {
return {data: post};
},
scrollPostListToBottom: jest.fn(),
};

function createPost({
Expand Down
2 changes: 2 additions & 0 deletions components/create_post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {Posts, Preferences as PreferencesRedux} from 'mattermost-redux/constants
import {connectionErrorCount} from 'selectors/views/system';

import {addReaction, createPost, setEditingPost} from 'actions/post_actions.jsx';
import {scrollPostListToBottom} from 'actions/views/channel';
import {selectPostFromRightHandSideSearchByPostId} from 'actions/views/rhs';
import {executeCommand} from 'actions/command';
import {runMessageWillBePostedHooks} from 'actions/hooks';
Expand Down Expand Up @@ -117,6 +118,7 @@ function mapDispatchToProps(dispatch) {
executeCommand,
getChannelTimezones,
runMessageWillBePostedHooks,
scrollPostListToBottom,
}, dispatch),
};
}
Expand Down
6 changes: 6 additions & 0 deletions components/post_view/post_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import PropTypes from 'prop-types';
import React from 'react';
import AutoSizer from 'react-virtualized-auto-sizer';
import {DynamicSizeList} from 'react-window';

import {debounce} from 'mattermost-redux/actions/helpers';
import EventEmitter from 'mattermost-redux/utils/event_emitter';

import LoadingScreen from 'components/loading_screen.jsx';

Expand Down Expand Up @@ -128,6 +130,8 @@ export default class PostList extends React.PureComponent {
this.props.actions.checkAndSetMobileView();

window.addEventListener('resize', this.handleWindowResize);

EventEmitter.addListener('scroll_post_list_to_bottom', this.scrollToBottom);
}

getSnapshotBeforeUpdate(prevProps, prevState) {
Expand Down Expand Up @@ -170,6 +174,8 @@ export default class PostList extends React.PureComponent {
componentWillUnmount() {
this.mounted = false;
window.removeEventListener('resize', this.handleWindowResize);

EventEmitter.removeListener('scroll_post_list_to_bottom', this.scrollToBottom);
}

static getDerivedStateFromProps(props, state) {
Expand Down

0 comments on commit 2837bb3

Please sign in to comment.