update some documentation

This commit is contained in:
Shpuld Shpuldson 2020-11-19 12:35:21 +02:00
parent 1cd222d85c
commit 419df9d446
2 changed files with 8 additions and 12 deletions

View file

@ -175,13 +175,13 @@ const EmojiInput = {
showSuggestions: function (newValue) { showSuggestions: function (newValue) {
this.$emit('shown', newValue) this.$emit('shown', newValue)
}, },
textAtCaret: async function (textAtCaret) { textAtCaret: async function (newWord) {
const firstchar = textAtCaret.charAt(0) const firstchar = newWord.charAt(0)
this.suggestions = [] this.suggestions = []
if (textAtCaret === firstchar) return if (newWord === firstchar) return
const matchedSuggestions = await this.suggest(textAtCaret) const matchedSuggestions = await this.suggest(newWord)
// Async, cancel if textAtCaret has been updated while waiting // Async: cancel if textAtCaret has changed during wait
if (this.textAtCaret !== textAtCaret) return if (this.textAtCaret !== newWord) return
if (matchedSuggestions.length <= 0) return if (matchedSuggestions.length <= 0) return
this.suggestions = take(matchedSuggestions, 5) this.suggestions = take(matchedSuggestions, 5)
.map(({ imageUrl, ...rest }) => ({ .map(({ imageUrl, ...rest }) => ({

View file

@ -57,6 +57,8 @@ export const suggestEmoji = emojis => input => {
} }
export const suggestUsers = ({ dispatch, state }) => { export const suggestUsers = ({ dispatch, state }) => {
// Keep some persistent values in closure, most importantly for the
// custom debounce to work. Lodash debounce does not return a promise.
let suggestions = [] let suggestions = []
let previousQuery = '' let previousQuery = ''
let timeout = null let timeout = null
@ -66,7 +68,6 @@ export const suggestUsers = ({ dispatch, state }) => {
const debounceUserSearch = (query) => { const debounceUserSearch = (query) => {
cancelUserSearch && cancelUserSearch() cancelUserSearch && cancelUserSearch()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
clearTimeout(timeout)
timeout = setTimeout(() => { timeout = setTimeout(() => {
userSearch(query).then(resolve).catch(reject) userSearch(query).then(resolve).catch(reject)
}, 300) }, 300)
@ -95,11 +96,6 @@ export const suggestUsers = ({ dispatch, state }) => {
user => user =>
user.screen_name.toLowerCase().startsWith(noPrefix) || user.screen_name.toLowerCase().startsWith(noPrefix) ||
user.name.toLowerCase().startsWith(noPrefix) user.name.toLowerCase().startsWith(noPrefix)
/* taking only 20 results so that sorting is a bit cheaper, we display
* only 5 anyway. could be inaccurate, but we ideally we should query
* backend anyway
*/
).slice(0, 20).sort((a, b) => { ).slice(0, 20).sort((a, b) => {
let aScore = 0 let aScore = 0
let bScore = 0 let bScore = 0