mattermost-mobile/app/actions/views/select_team.js
enahum ecf39f61dd Various fixes & improvements (#611)
* RN-166 follow user prefs for join/leave messages

* RN-158 Fix Android input textbox offscreen issue

* RN-181 Use device locale as default locale

* Upgrade mattermost-redux

* Fix TouchableHighlight in the channel drawer items

* Update channel title when switching channels

* Fix channel name title when switching teams

* Fix unit test
2017-06-08 15:40:29 -04:00

44 lines
1.4 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {batchActions} from 'redux-batched-actions';
import {ChannelTypes, TeamTypes} from 'mattermost-redux/action_types';
import {setChannelDisplayName} from './channel';
export function handleTeamChange(team) {
return async (dispatch, getState) => {
const {currentTeamId} = getState().entities.teams;
if (currentTeamId === team.id) {
return;
}
const state = getState();
const lastChannelId = state.views.team.lastChannelForTeam[team.id] || '';
dispatch(setChannelDisplayName(''), getState);
dispatch(batchActions([
{type: TeamTypes.SELECT_TEAM, data: team.id},
{type: ChannelTypes.SELECT_CHANNEL, data: lastChannelId}
]), getState);
};
}
export function selectFirstAvailableTeam() {
return async (dispatch, getState) => {
const {teams: allTeams, myMembers} = getState().entities.teams;
const teams = Object.keys(myMembers).map((key) => allTeams[key]);
const firstTeam = Object.values(teams).sort((a, b) => a.display_name.localeCompare(b.display_name))[0];
if (firstTeam) {
handleTeamChange(firstTeam)(dispatch, getState);
}
};
}
export default {
handleTeamChange,
selectFirstAvailableTeam
};