From 9cc000f6e23d75e826c4468dd5c3977397e58e57 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Mon, 2 Nov 2015 16:04:14 -0800 Subject: Functionalized code --- web/react/utils/utils.jsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'web/react/utils/utils.jsx') diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 296307bc6..35c6e29b6 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -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; +} -- cgit v1.2.3-1-g7c22