diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 361b9b73b8..cbe54b83c4 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -155,10 +155,13 @@ exports.render_emoji = function (item) { return exports.render_typeahead_item(args); }; -// manipulate prefix_sort to select popular emojis first -// This is kinda a hack and so probably not our long-term solution. -function emoji_prefix_sort(query, objs, get_item) { - const prefix_sort = util.prefix_sort(query, objs, get_item); +exports.sort_emojis = function (objs, query) { + const prefix_sort = util.prefix_sort( + query, + objs, + (x) => x.emoji_name + ); + const popular_emoji_matches = []; const other_emoji_matches = []; prefix_sort.matches.forEach(function (obj) { @@ -168,8 +171,13 @@ function emoji_prefix_sort(query, objs, get_item) { other_emoji_matches.push(obj); } }); - return { matches: popular_emoji_matches.concat(other_emoji_matches), rest: prefix_sort.rest }; -} + + return [].concat( + popular_emoji_matches, + other_emoji_matches, + prefix_sort.rest + ); +}; exports.sorter = function (query, objs, get_item) { const results = util.prefix_sort(query, objs, get_item); @@ -411,12 +419,6 @@ exports.sort_slash_commands = function (matches, query) { return results.matches.concat(results.rest); }; -exports.sort_emojis = function (matches, query) { - // TODO: sort by category in v2 - const results = emoji_prefix_sort(query, matches, function (x) { return x.emoji_name; }); - return results.matches.concat(results.rest); -}; - // Gives stream a score from 0 to 3 based on its activity function activity_score(sub) { let stream_score = 0;