remove search blocker, fix debounce params

This commit is contained in:
Shpuld Shpuldson 2020-06-18 12:29:13 +03:00
parent ebf4321e64
commit 9c884fef11
2 changed files with 20 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { debounce } from 'lodash' import debounce from 'lodash/debounce'
/** /**
* suggest - generates a suggestor function to be used by emoji-input * suggest - generates a suggestor function to be used by emoji-input
* data: object providing source information for specific types of suggestions: * data: object providing source information for specific types of suggestions:
@ -13,7 +13,7 @@ import { debounce } from 'lodash'
const debounceUserSearch = debounce((data, input) => { const debounceUserSearch = debounce((data, input) => {
data.updateUsersList(input) data.updateUsersList(input)
}, 500, { leading: true, trailing: false }) }, 500)
export default data => input => { export default data => input => {
const firstChar = input[0] const firstChar = input[0]
@ -97,8 +97,8 @@ export const suggestUsers = data => input => {
replacement: '@' + screen_name + ' ' replacement: '@' + screen_name + ' '
})) }))
// BE search users if there are no matches // BE search users to get more comprehensive results
if (newUsers.length === 0 && data.updateUsersList) { if (data.updateUsersList) {
debounceUserSearch(data, noPrefix) debounceUserSearch(data, noPrefix)
} }
return newUsers return newUsers

View File

@ -225,6 +225,12 @@ export const mutations = {
signUpFailure (state, errors) { signUpFailure (state, errors) {
state.signUpPending = false state.signUpPending = false
state.signUpErrors = errors 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: {}, usersObject: {},
signUpPending: false, signUpPending: false,
signUpErrors: [], signUpErrors: [],
relationships: {} relationships: {},
recentQueries: []
} }
const users = { const users = {
@ -428,10 +435,15 @@ const users = {
store.commit('setUserForNotification', notification) store.commit('setUserForNotification', notification)
}) })
}, },
searchUsers (store, { query }) { searchUsers ({ rootState, commit }, { query }) {
return store.rootState.api.backendInteractor.searchUsers({ 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) => { .then((users) => {
store.commit('addNewUsers', users) commit('addRecentQuery', query)
commit('addNewUsers', users)
return users return users
}) })
}, },