diff options
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r-- | web/react/utils/utils.jsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index c82bd1065..e8d34dccd 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -1104,3 +1104,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; +} |