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

MM-13209: use textbox channel from context #2108

Merged
merged 5 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MM-13209: fix textbox to bind channel from props
This avoids relying on a global notion of the current channel, which only applies to the centre and not the RHS.
  • Loading branch information
lieut-data committed Nov 29, 2018
commit a170ad9c411987606950bf4e382a7b2f321ac985
7 changes: 3 additions & 4 deletions actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE.txt for license information.

import {leaveChannel as leaveChannelRedux, joinChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels';
import {getChannel, getChannelByName, getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels';
import {getChannel, getChannelByName} 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';
Expand Down Expand Up @@ -102,13 +102,12 @@ export function leaveChannel(channelId) {
};
}

export function autocompleteUsersInChannel(prefix) {
export function autocompleteUsersInChannel(prefix, channelId) {
return async (dispatch, getState) => {
const state = getState();
const currentTeamId = getCurrentTeamId(state);
const currentChannelId = getCurrentChannelId(state);

return dispatch(autocompleteUsers(prefix, currentTeamId, currentChannelId));
return dispatch(autocompleteUsers(prefix, currentTeamId, channelId));
};
}

21 changes: 13 additions & 8 deletions components/textbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {getCurrentUserId, getProfilesInCurrentChannel, getProfilesNotInCurrentChannel} from 'mattermost-redux/selectors/entities/users';
import {getCurrentUserId, makeGetProfilesInChannel, makeGetProfilesNotInChannel} from 'mattermost-redux/selectors/entities/users';

import {autocompleteUsersInChannel} from 'actions/views/channel';

import Textbox from './textbox.jsx';

const mapStateToProps = (state) => ({
currentUserId: getCurrentUserId(state),
profilesInChannel: getProfilesInCurrentChannel(state),
profilesNotInChannel: getProfilesNotInCurrentChannel(state),
});
const mapStateToProps = () => {
const getProfilesInChannel = makeGetProfilesInChannel();
const getProfilesNotInChannel = makeGetProfilesNotInChannel();

return (state, ownProps) => ({
currentUserId: getCurrentUserId(state),
profilesInChannel: getProfilesInChannel(state, ownProps.channelId, true),
profilesNotInChannel: getProfilesNotInChannel(state, ownProps.channelId, true),
});
};

const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch, ownProps) => ({
actions: bindActionCreators({
autocompleteUsersInChannel,
autocompleteUsersInChannel: (prefix) => autocompleteUsersInChannel(prefix, ownProps.channelId),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just have the Textbox pass the channelId into the action when it calls it? Since it's coming from ownProps, the Textbox knows about channelId either way, and I don't have a good understanding of how ownProps works with mapDispatchToProps to know if doing this has any side effects

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

}, dispatch),
});

Expand Down