Fix race condition when selecting channel in PN (#723)

* Fix race condition when selecting channel in PN

* Feedback review
This commit is contained in:
enahum 2017-07-07 16:37:31 -04:00 committed by GitHub
parent 8afd7fe1cd
commit 458a2be333
2 changed files with 11 additions and 8 deletions

View file

@ -47,7 +47,7 @@ export function goToNotification(notification) {
dispatch(setChannelDisplayName(''));
if (teamId) {
handleTeamChange(teams[teamId])(dispatch, getState);
handleTeamChange(teams[teamId], false)(dispatch, getState);
await loadChannelsIfNecessary(teamId)(dispatch, getState);
} else {
await selectFirstAvailableTeam()(dispatch, getState);

View file

@ -10,7 +10,7 @@ import {NavigationTypes} from 'app/constants';
import {setChannelDisplayName} from './channel';
export function handleTeamChange(team) {
export function handleTeamChange(team, selectChannel = true) {
return async (dispatch, getState) => {
const {currentTeamId} = getState().entities.teams;
if (currentTeamId === team.id) {
@ -18,14 +18,17 @@ export function handleTeamChange(team) {
}
const state = getState();
const lastChannelId = state.views.team.lastChannelForTeam[team.id] || '';
const actions = [
setChannelDisplayName(''),
{type: TeamTypes.SELECT_TEAM, data: team.id}
];
dispatch(setChannelDisplayName(''), getState);
if (selectChannel) {
const lastChannelId = state.views.team.lastChannelForTeam[team.id] || '';
actions.push({type: ChannelTypes.SELECT_CHANNEL, data: lastChannelId});
}
dispatch(batchActions([
{type: TeamTypes.SELECT_TEAM, data: team.id},
{type: ChannelTypes.SELECT_CHANNEL, data: lastChannelId}
]), getState);
dispatch(batchActions(actions), getState);
};
}