Functionalized code
Этот коммит содержится в:
@@ -18,24 +18,8 @@ function getStateFromStores() {
|
||||
teams.push(teamsObject[teamId]);
|
||||
}
|
||||
}
|
||||
teams.sort((teamA, teamB) => {
|
||||
let teamADisplayName = '';
|
||||
let teamBDisplayName = '';
|
||||
|
||||
if (teamA && teamA.display_name) {
|
||||
teamADisplayName = teamA.display_name.toLowerCase();
|
||||
}
|
||||
if (teamB && teamB.display_name) {
|
||||
teamBDisplayName = teamB.display_name.toLowerCase();
|
||||
}
|
||||
|
||||
if (teamADisplayName < teamBDisplayName) {
|
||||
return -1;
|
||||
} else if (teamADisplayName > teamBDisplayName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
teams.sort(Utils.sortByDisplayName);
|
||||
return {teams};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var Utils;
|
||||
var Constants = require('../utils/constants.jsx');
|
||||
var ActionTypes = Constants.ActionTypes;
|
||||
|
||||
@@ -183,26 +184,11 @@ class ChannelStoreClass extends EventEmitter {
|
||||
channels.push(channel);
|
||||
}
|
||||
|
||||
channels.sort((a, b) => {
|
||||
let channelADisplayName = '';
|
||||
let channelBDisplayName = '';
|
||||
|
||||
if (a && a.display_name) {
|
||||
channelADisplayName = a.display_name.toLowerCase();
|
||||
}
|
||||
if (b && b.display_name) {
|
||||
channelBDisplayName = b.display_name.toLowerCase();
|
||||
}
|
||||
|
||||
if (channelADisplayName < channelBDisplayName) {
|
||||
return -1;
|
||||
}
|
||||
if (channelADisplayName > channelBDisplayName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
if (!Utils) {
|
||||
Utils = require('../utils/utils.jsx'); //eslint-disable-line global-require
|
||||
}
|
||||
|
||||
channels.sort(Utils.sortByDisplayName);
|
||||
this.pStoreChannels(channels);
|
||||
}
|
||||
pStoreChannels(channels) {
|
||||
|
||||
@@ -1090,3 +1090,24 @@ export function openDirectChannelToUser(user, successCb, errorCb) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Use when sorting multiple channels or teams by their `display_name` field
|
||||
export function sortByDisplayName(a, b) {
|
||||
let aDisplayName = '';
|
||||
let bDisplayName = '';
|
||||
|
||||
if (a && a.display_name) {
|
||||
aDisplayName = a.display_name.toLowerCase();
|
||||
}
|
||||
if (b && b.display_name) {
|
||||
bDisplayName = b.display_name.toLowerCase();
|
||||
}
|
||||
|
||||
if (aDisplayName < bDisplayName) {
|
||||
return -1;
|
||||
}
|
||||
if (aDisplayName > bDisplayName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user