sorting
This commit is contained in:
parent
0a778160cc
commit
a3cc8cc5d8
|
@ -29,7 +29,21 @@ function suggestUsers (users) {
|
|||
user.screen_name.toLowerCase().startsWith(noPrefix) ||
|
||||
user.name.toLowerCase().startsWith(noPrefix)
|
||||
/* eslint-disable camelcase */
|
||||
).map(({ screen_name, name, profile_image_url_original }) => ({
|
||||
).slice(0, 20).sort((a, b) => {
|
||||
let aScore = 0
|
||||
let bScore = 0
|
||||
|
||||
aScore += a.screen_name.toLowerCase().startsWith(noPrefix) * 2
|
||||
aScore += a.name.toLowerCase().startsWith(noPrefix)
|
||||
bScore += b.screen_name.toLowerCase().startsWith(noPrefix) * 2
|
||||
bScore += b.name.toLowerCase().startsWith(noPrefix)
|
||||
|
||||
const diff = bScore * 10 - aScore * 10
|
||||
const nameAlphabetically = a.name > b.name ? 1 : -1
|
||||
const screenNameAlphabetically = a.screen_name > b.screen_name ? 1 : -1
|
||||
|
||||
return diff + nameAlphabetically + screenNameAlphabetically
|
||||
}).map(({ screen_name, name, profile_image_url_original }) => ({
|
||||
displayText: screen_name,
|
||||
detailText: name,
|
||||
imageUrl: profile_image_url_original,
|
||||
|
|
Loading…
Reference in New Issue