From 8f821b0a45cb239e3a57f956d1fca78d9df55152 Mon Sep 17 00:00:00 2001 From: Maximilian Weiler <16721506+maweil@users.noreply.github.com> Date: Wed, 13 Oct 2021 23:10:26 +0200 Subject: [PATCH 1/2] feature: Show direct match on top for user search - Fixes #14350 Signed-off-by: Maximilian Weiler <16721506+maweil@users.noreply.github.com> --- web_src/js/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 71e5691179a2..8e27816db29d 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -2233,15 +2233,21 @@ function searchUsers() { url: `${AppSubUrl}/api/v1/users/search?q={query}`, onResponse(response) { const items = []; + const searchQuery = $searchUserBox.find('input').val(); $.each(response.data, (_i, item) => { let title = item.login; if (item.full_name && item.full_name.length > 0) { title += ` (${htmlEscape(item.full_name)})`; } - items.push({ + const resultItem = { title, image: item.avatar_url - }); + }; + if (searchQuery === item.login) { + items.unshift(resultItem); + } else { + items.push(resultItem); + } }); return {results: items}; From 2b38f05ef0b7e4a0ce5f37e78c27fa4b0fe5cb80 Mon Sep 17 00:00:00 2001 From: Maximilian Weiler <16721506+maweil@users.noreply.github.com> Date: Thu, 14 Oct 2021 21:42:56 +0200 Subject: [PATCH 2/2] feature: Compare usernames case insensitive --- web_src/js/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 8e27816db29d..bc9725da9545 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -2233,7 +2233,7 @@ function searchUsers() { url: `${AppSubUrl}/api/v1/users/search?q={query}`, onResponse(response) { const items = []; - const searchQuery = $searchUserBox.find('input').val(); + const searchQueryUppercase = $searchUserBox.find('input').val().toUpperCase(); $.each(response.data, (_i, item) => { let title = item.login; if (item.full_name && item.full_name.length > 0) { @@ -2243,7 +2243,7 @@ function searchUsers() { title, image: item.avatar_url }; - if (searchQuery === item.login) { + if (searchQueryUppercase === item.login.toUpperCase()) { items.unshift(resultItem); } else { items.push(resultItem);