Show town square when selecting a team (#166)

Now selects the first channel if the default channel can’t be found
This commit is contained in:
Chris Duarte 2017-01-19 06:55:32 -08:00 committed by Harrison Healey
parent 1566a79c93
commit c94a0840fd

View file

@ -95,12 +95,13 @@ export function selectInitialChannel(teamId) {
return async (dispatch, getState) => {
const channels = getState().entities.channels.channels;
for (const channel of Object.values(channels)) {
// TODO figure out how to handle when we can't find the town square
if (channel.team_id === teamId && channel.name === Constants.DEFAULT_CHANNEL) {
await selectChannel(channel.id)(dispatch, getState);
break;
}
const channel = Object.values(channels).find((c) => c.team_id === teamId && c.name === Constants.DEFAULT_CHANNEL);
if (channel) {
await selectChannel(channel.id)(dispatch, getState);
} else {
// Handle case when the default channel cannot be found
const firstChannel = Object.values(channels)[0];
await selectChannel(firstChannel.id)(dispatch, getState);
}
};
}