From 2a75ee022c98a72124dd072ee8c82e8bc0108321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 27 Sep 2018 19:02:02 +0200 Subject: [PATCH] MM-11606: Back to prev channel on close archived channel (#2183) --- app/actions/views/channel.js | 2 ++ app/components/post_textbox/index.js | 9 ++++----- app/components/post_textbox/post_textbox.js | 12 ++++-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index 94de6fe28d..55e529bcfa 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -297,6 +297,8 @@ export function selectPenultimateChannel(teamId) { (lastChannel.delete_at === 0 || viewArchivedChannels) && (lastChannel.team_id === teamId || isDMVisible || isGMVisible) ) { + dispatch(setChannelLoading(true)); + dispatch(setChannelDisplayName(lastChannel.display_name)); dispatch(handleSelectChannel(lastChannelId)); dispatch(markChannelAsRead(lastChannelId)); return; diff --git a/app/components/post_textbox/index.js b/app/components/post_textbox/index.js index 71e7e4779f..ca00d1f5e1 100644 --- a/app/components/post_textbox/index.js +++ b/app/components/post_textbox/index.js @@ -7,14 +7,14 @@ import {connect} from 'react-redux'; import {General} from 'mattermost-redux/constants'; import {createPost} from 'mattermost-redux/actions/posts'; import {setStatus} from 'mattermost-redux/actions/users'; -import {getCurrentChannel, isCurrentChannelReadOnly, getDefaultChannel} from 'mattermost-redux/selectors/entities/channels'; +import {getCurrentChannel, isCurrentChannelReadOnly} from 'mattermost-redux/selectors/entities/channels'; import {canUploadFilesOnMobile, getConfig} from 'mattermost-redux/selectors/entities/general'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId, getStatusForUserId} from 'mattermost-redux/selectors/entities/users'; import {executeCommand} from 'app/actions/views/command'; import {addReactionToLatestPost} from 'app/actions/views/emoji'; -import {handlePostDraftChanged, setChannelDisplayName, setChannelLoading} from 'app/actions/views/channel'; +import {handlePostDraftChanged, selectPenultimateChannel} from 'app/actions/views/channel'; import {handleClearFiles, handleClearFailedFiles, handleRemoveLastFile, initUploadFiles} from 'app/actions/views/file_upload'; import {handleCommentDraftChanged, handleCommentDraftSelectionChanged} from 'app/actions/views/thread'; import {userTyping} from 'app/actions/views/typing'; @@ -44,6 +44,7 @@ function mapStateToProps(state, ownProps) { return { channelId: ownProps.channelId || (currentChannel ? currentChannel.id : ''), + channelTeamId: currentChannel.team_id, canUploadFiles: canUploadFilesOnMobile(state), channelIsLoading: state.views.channel.loading, channelIsReadOnly: isCurrentChannelReadOnly(state), @@ -56,7 +57,6 @@ function mapStateToProps(state, ownProps) { theme: getTheme(state), uploadFileRequestStatus: state.requests.files.uploadFiles.status, value: currentDraft.draft, - defaultChannel: getDefaultChannel(state), }; } @@ -75,8 +75,7 @@ function mapDispatchToProps(dispatch) { userTyping, handleCommentDraftSelectionChanged, setStatus, - setChannelDisplayName, - setChannelLoading, + selectPenultimateChannel, }, dispatch), }; } diff --git a/app/components/post_textbox/post_textbox.js b/app/components/post_textbox/post_textbox.js index 7939a5acfe..d5f2ebb5c2 100644 --- a/app/components/post_textbox/post_textbox.js +++ b/app/components/post_textbox/post_textbox.js @@ -38,11 +38,11 @@ export default class PostTextbox extends PureComponent { userTyping: PropTypes.func.isRequired, handleCommentDraftSelectionChanged: PropTypes.func.isRequired, setStatus: PropTypes.func.isRequired, - setChannelDisplayName: PropTypes.func.isRequired, - setChannelLoading: PropTypes.func.isRequired, + selectPenultimateChannel: PropTypes.func.isRequired, }).isRequired, canUploadFiles: PropTypes.bool.isRequired, channelId: PropTypes.string.isRequired, + channelTeamId: PropTypes.string.isRequired, channelIsLoading: PropTypes.bool, channelIsReadOnly: PropTypes.bool.isRequired, currentUserId: PropTypes.string.isRequired, @@ -56,7 +56,6 @@ export default class PostTextbox extends PureComponent { value: PropTypes.string.isRequired, userIsOutOfOffice: PropTypes.bool.isRequired, channelIsArchived: PropTypes.bool, - defaultChannel: PropTypes.object, onCloseChannel: PropTypes.func, }; @@ -460,11 +459,8 @@ export default class PostTextbox extends PureComponent { }; onCloseChannelPress = () => { - const {defaultChannel, channelId, onCloseChannel} = this.props; - const {setChannelDisplayName, setChannelLoading} = this.props.actions; - setChannelLoading(true); - setChannelDisplayName(defaultChannel.display_name); - EventEmitter.emit('switch_channel', defaultChannel, channelId); + const {onCloseChannel, channelTeamId} = this.props; + this.props.actions.selectPenultimateChannel(channelTeamId); if (onCloseChannel) { onCloseChannel(); }