From 44dea9f3646a5c27083dfe6cd6b1522e11c7dc69 Mon Sep 17 00:00:00 2001 From: xenofem Date: Sun, 9 Feb 2020 17:25:24 -0500 Subject: Allow emoji suggestions based on a match anywhere in the emoji name, but improve sorting --- src/components/emoji_input/suggestor.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/components/emoji_input') diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index aec5c39d..9e437ccc 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -29,17 +29,21 @@ export default data => input => { export const suggestEmoji = emojis => input => { const noPrefix = input.toLowerCase().substr(1) return emojis - .filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix)) + .filter(({ displayText }) => displayText.toLowerCase().match(noPrefix)) .sort((a, b) => { let aScore = 0 let bScore = 0 - // Make custom emojis a priority - aScore += a.imageUrl ? 10 : 0 - bScore += b.imageUrl ? 10 : 0 + // Prioritize emoji that start with the input string + aScore += a.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0 + bScore += b.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0 - // Sort alphabetically - const alphabetically = a.displayText > b.displayText ? 1 : -1 + // Sort by length + aScore -= a.displayText.length + bScore -= b.displayText.length + + // Break ties alphabetically + const alphabetically = a.displayText > b.displayText ? 0.5 : -0.5 return bScore - aScore + alphabetically }) -- cgit v1.2.3-70-g09d2 From 02864bc07b2ab2f08232ba1c4c27079454dc87ef Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 10 Feb 2020 09:32:07 -0500 Subject: Prioritize custom emoji a lot and boost exact matches to the top --- src/components/emoji_input/suggestor.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/components/emoji_input') diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index 9e437ccc..15a71eff 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -34,7 +34,15 @@ export const suggestEmoji = emojis => input => { let aScore = 0 let bScore = 0 - // Prioritize emoji that start with the input string + // An exact match always wins + aScore += a.displayText.toLowerCase() === noPrefix ? 200 : 0 + bScore += b.displayText.toLowerCase() === noPrefix ? 200 : 0 + + // Prioritize custom emoji a lot + aScore += a.imageUrl ? 100 : 0 + bScore += b.imageUrl ? 100 : 0 + + // Prioritize prefix matches somewhat aScore += a.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0 bScore += b.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0 -- cgit v1.2.3-70-g09d2 From 9c884fef11e52541ab64508c9a9e0b8694432cbb Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 12:29:13 +0300 Subject: remove search blocker, fix debounce params --- src/components/emoji_input/suggestor.js | 8 ++++---- src/modules/users.js | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/components/emoji_input') diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index 15a71eff..91d5cfb9 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -1,4 +1,4 @@ -import { debounce } from 'lodash' +import debounce from 'lodash/debounce' /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: @@ -13,7 +13,7 @@ import { debounce } from 'lodash' const debounceUserSearch = debounce((data, input) => { data.updateUsersList(input) -}, 500, { leading: true, trailing: false }) +}, 500) export default data => input => { const firstChar = input[0] @@ -97,8 +97,8 @@ export const suggestUsers = data => input => { replacement: '@' + screen_name + ' ' })) - // BE search users if there are no matches - if (newUsers.length === 0 && data.updateUsersList) { + // BE search users to get more comprehensive results + if (data.updateUsersList) { debounceUserSearch(data, noPrefix) } return newUsers diff --git a/src/modules/users.js b/src/modules/users.js index f9329f2a..a640fb3b 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -225,6 +225,12 @@ export const mutations = { signUpFailure (state, errors) { state.signUpPending = false state.signUpErrors = errors + }, + addRecentQuery (state, query) { + state.recentQueries = state.recentQueries.concat(query) + if (state.recentQueries.length > 10) { + state.recentQueries = state.recentQueries.slice(1) + } } } @@ -251,7 +257,8 @@ export const defaultState = { usersObject: {}, signUpPending: false, signUpErrors: [], - relationships: {} + relationships: {}, + recentQueries: [] } const users = { @@ -428,10 +435,15 @@ const users = { store.commit('setUserForNotification', notification) }) }, - searchUsers (store, { query }) { - return store.rootState.api.backendInteractor.searchUsers({ query }) + searchUsers ({ rootState, commit }, { query }) { + // Don't fetch if this query was already done recently + if (rootState.users.recentQueries.includes(query)) { + return [] + } + return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { - store.commit('addNewUsers', users) + commit('addRecentQuery', query) + commit('addNewUsers', users) return users }) }, -- cgit v1.2.3-70-g09d2 From f1175b4e9b9558e304bc56e1a3d4c9daafefd89f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 13:41:04 +0300 Subject: revert import style --- src/components/emoji_input/suggestor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/emoji_input') diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index 91d5cfb9..8330345b 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -1,4 +1,4 @@ -import debounce from 'lodash/debounce' +import { debounce } from 'lodash' /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: -- cgit v1.2.3-70-g09d2