mirror of
https://git.youjo.love/youjo/youjo-fe.git
synced 2024-11-20 13:59:55 +01:00
improved algorithm, possibly speed too
This commit is contained in:
parent
f1e1f20a8d
commit
cff202241b
2 changed files with 12 additions and 6 deletions
|
@ -11,14 +11,17 @@ const filterByKeyword = (list, keyword = '') => {
|
|||
if (keyword === '') return list
|
||||
|
||||
const keywordLowercase = keyword.toLowerCase()
|
||||
const orderedEmojiList = []
|
||||
let orderedEmojiList = []
|
||||
for (const emoji of list) {
|
||||
const indexOfKeyword = emoji.displayText.toLowerCase().indexOf(keywordLowercase)
|
||||
if (indexOfKeyword > -1) {
|
||||
orderedEmojiList.splice(indexOfKeyword, 0, emoji)
|
||||
if (!Array.isArray(orderedEmojiList[keywordLowercase])) {
|
||||
orderedEmojiList[keywordLowercase] = []
|
||||
}
|
||||
orderedEmojiList[keywordLowercase].push(emoji)
|
||||
}
|
||||
}
|
||||
return orderedEmojiList
|
||||
return orderedEmojiList.flat()
|
||||
}
|
||||
|
||||
const EmojiPicker = {
|
||||
|
|
|
@ -29,14 +29,17 @@ const ReactButton = {
|
|||
emojis () {
|
||||
if (this.filterWord !== '') {
|
||||
const filterWordLowercase = this.filterWord.toLowerCase()
|
||||
const orderedEmojiList = []
|
||||
let orderedEmojiList = []
|
||||
for (const emoji of this.$store.state.instance.emoji) {
|
||||
const indexOfFilterWord = emoji.displayText.toLowerCase().indexOf(filterWordLowercase)
|
||||
if (indexOfFilterWord > -1) {
|
||||
orderedEmojiList.splice(indexOfFilterWord, 0, emoji)
|
||||
if (!Array.isArray(orderedEmojiList[indexOfFilterWord])) {
|
||||
orderedEmojiList[indexOfFilterWord] = []
|
||||
}
|
||||
orderedEmojiList[indexOfFilterWord].push(emoji)
|
||||
}
|
||||
}
|
||||
return orderedEmojiList
|
||||
return orderedEmojiList.flat()
|
||||
}
|
||||
return this.$store.state.instance.emoji || []
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue