forked from Ivasoft/mattermost-mobile
* update eslint's `comma-dangle` rule to `always-multiline` * add check and fix scripts to package.json * Invoke `yarn fix` to adopt the updated eslint rules. No other changes are included.
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {combineReducers} from 'redux';
|
|
import {TeamTypes} from 'mattermost-redux/action_types';
|
|
|
|
import {ViewTypes} from 'app/constants';
|
|
|
|
function lastTeamId(state = '', action) {
|
|
switch (action.type) {
|
|
case TeamTypes.SELECT_TEAM:
|
|
return action.data;
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function lastChannelForTeam(state = {}, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.SET_LAST_CHANNEL_FOR_TEAM: {
|
|
const team = state[action.teamId];
|
|
const channelIds = [];
|
|
|
|
if (!action.channelId) {
|
|
return state;
|
|
}
|
|
|
|
if (team) {
|
|
channelIds.push(...team);
|
|
const index = channelIds.indexOf(action.channelId);
|
|
if (index === -1) {
|
|
channelIds.unshift(action.channelId);
|
|
channelIds.slice(0, 5);
|
|
} else {
|
|
channelIds.splice(index, 1);
|
|
channelIds.unshift(action.channelId);
|
|
}
|
|
} else {
|
|
channelIds.push(action.channelId);
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
[action.teamId]: channelIds,
|
|
};
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default combineReducers({
|
|
lastTeamId,
|
|
lastChannelForTeam,
|
|
});
|