From 9c884fef11e52541ab64508c9a9e0b8694432cbb Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 12:29:13 +0300 Subject: [PATCH 1/5] 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(-) 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 }) }, From abbad84b00fbfe365ba6bf5015278b296265b98a Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 12:56:22 +0300 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dfe741c..f2580bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Uploading and drag-dropping multiple files works correctly now. - Subject field now appears disabled when posting - Fix status ellipsis menu being cut off in notifications column +- Fixed autocomplete sometimes not returning the right user when there's already some results ## [2.0.3] - 2020-05-02 ### Fixed From fa7bcb74cecb8af095e6e22271243f2d51835f39 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 13:00:09 +0300 Subject: [PATCH 3/5] return the correct promise type from action --- src/modules/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/users.js b/src/modules/users.js index a640fb3b..df710ac9 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -438,7 +438,7 @@ const users = { searchUsers ({ rootState, commit }, { query }) { // Don't fetch if this query was already done recently if (rootState.users.recentQueries.includes(query)) { - return [] + return Promise.resolve([]) } return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { From f1175b4e9b9558e304bc56e1a3d4c9daafefd89f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 13:41:04 +0300 Subject: [PATCH 4/5] revert import style --- src/components/emoji_input/suggestor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 4e0b4427a969b2d0584a3a1c1ffd3fe3fbfc2998 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Thu, 18 Jun 2020 14:19:21 +0300 Subject: [PATCH 5/5] remove recentqueries thing --- src/modules/users.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/modules/users.js b/src/modules/users.js index df710ac9..5e32bb49 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -225,12 +225,6 @@ 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) - } } } @@ -257,8 +251,7 @@ export const defaultState = { usersObject: {}, signUpPending: false, signUpErrors: [], - relationships: {}, - recentQueries: [] + relationships: {} } const users = { @@ -436,13 +429,8 @@ const users = { }) }, searchUsers ({ rootState, commit }, { query }) { - // Don't fetch if this query was already done recently - if (rootState.users.recentQueries.includes(query)) { - return Promise.resolve([]) - } return rootState.api.backendInteractor.searchUsers({ query }) .then((users) => { - commit('addRecentQuery', query) commit('addNewUsers', users) return users })