aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTusooa Zhu <tusooa@kazv.moe>2022-07-07 23:10:06 -0400
committerTusooa Zhu <tusooa@kazv.moe>2022-09-18 13:19:54 -0400
commit5d6f3a5c8bd3acc53e51b4300c93051ddc1b627b (patch)
tree2c567a64909e3220d78411d9a6c1ba2614bf4926 /src
parent09bcb6a5b176a9451d842a32dae64a214aa5ce8c (diff)
Tweak efficiency when changing filter keywords in emoji picker
Diffstat (limited to 'src')
-rw-r--r--src/components/emoji_picker/emoji_picker.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js
index 3cb6f76d..6a7b5285 100644
--- a/src/components/emoji_picker/emoji_picker.js
+++ b/src/components/emoji_picker/emoji_picker.js
@@ -17,7 +17,7 @@ import {
faCode,
faFlag
} from '@fortawesome/free-solid-svg-icons'
-import { trim } from 'lodash'
+import { debounce, trim } from 'lodash'
library.add(
faBoxOpen,
@@ -86,7 +86,8 @@ const EmojiPicker = {
// Lazy-load only after the first time `showing` becomes true.
contentLoaded: false,
groupRefs: {},
- emojiRefs: {}
+ emojiRefs: {},
+ filteredEmojiGroups: []
}
},
components: {
@@ -206,6 +207,7 @@ const EmojiPicker = {
const oldContentLoaded = this.contentLoaded
this.contentLoaded = true
this.waitForDomAndInitializeLazyLoad()
+ this.filteredEmojiGroups = this.getFilteredEmojiGroups()
if (!oldContentLoaded) {
this.$nextTick(() => {
if (this.defaultGroup) {
@@ -213,15 +215,24 @@ const EmojiPicker = {
}
})
}
+ },
+ getFilteredEmojiGroups () {
+ return this.allEmojiGroups
+ .map(group => ({
+ ...group,
+ emojis: filterByKeyword(group.emojis, trim(this.keyword))
+ }))
+ .filter(group => group.emojis.length > 0)
}
},
watch: {
keyword () {
this.onScroll()
- this.waitForDomAndInitializeLazyLoad()
+ this.debouncedHandleKeywordChange()
},
allCustomGroups () {
this.waitForDomAndInitializeLazyLoad()
+ this.filteredEmojiGroups = this.getFilteredEmojiGroups()
},
showing (val) {
if (val) {
@@ -266,16 +277,14 @@ const EmojiPicker = {
.map(([_, v]) => v)
.concat(this.unicodeEmojiGroups)
},
- filteredEmojiGroups () {
- return this.allEmojiGroups
- .map(group => ({
- ...group,
- emojis: filterByKeyword(group.emojis, trim(this.keyword))
- }))
- .filter(group => group.emojis.length > 0)
- },
stickerPickerEnabled () {
return (this.$store.state.instance.stickers || []).length !== 0
+ },
+ debouncedHandleKeywordChange () {
+ return debounce(() => {
+ this.waitForDomAndInitializeLazyLoad()
+ this.filteredEmojiGroups = this.getFilteredEmojiGroups()
+ }, 500)
}
}
}