Tweak efficiency when changing filter keywords in emoji picker
This commit is contained in:
parent
09bcb6a5b1
commit
5d6f3a5c8b
@ -17,7 +17,7 @@ import {
|
|||||||
faCode,
|
faCode,
|
||||||
faFlag
|
faFlag
|
||||||
} from '@fortawesome/free-solid-svg-icons'
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import { trim } from 'lodash'
|
import { debounce, trim } from 'lodash'
|
||||||
|
|
||||||
library.add(
|
library.add(
|
||||||
faBoxOpen,
|
faBoxOpen,
|
||||||
@ -86,7 +86,8 @@ const EmojiPicker = {
|
|||||||
// Lazy-load only after the first time `showing` becomes true.
|
// Lazy-load only after the first time `showing` becomes true.
|
||||||
contentLoaded: false,
|
contentLoaded: false,
|
||||||
groupRefs: {},
|
groupRefs: {},
|
||||||
emojiRefs: {}
|
emojiRefs: {},
|
||||||
|
filteredEmojiGroups: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
@ -206,6 +207,7 @@ const EmojiPicker = {
|
|||||||
const oldContentLoaded = this.contentLoaded
|
const oldContentLoaded = this.contentLoaded
|
||||||
this.contentLoaded = true
|
this.contentLoaded = true
|
||||||
this.waitForDomAndInitializeLazyLoad()
|
this.waitForDomAndInitializeLazyLoad()
|
||||||
|
this.filteredEmojiGroups = this.getFilteredEmojiGroups()
|
||||||
if (!oldContentLoaded) {
|
if (!oldContentLoaded) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.defaultGroup) {
|
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: {
|
watch: {
|
||||||
keyword () {
|
keyword () {
|
||||||
this.onScroll()
|
this.onScroll()
|
||||||
this.waitForDomAndInitializeLazyLoad()
|
this.debouncedHandleKeywordChange()
|
||||||
},
|
},
|
||||||
allCustomGroups () {
|
allCustomGroups () {
|
||||||
this.waitForDomAndInitializeLazyLoad()
|
this.waitForDomAndInitializeLazyLoad()
|
||||||
|
this.filteredEmojiGroups = this.getFilteredEmojiGroups()
|
||||||
},
|
},
|
||||||
showing (val) {
|
showing (val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
@ -266,16 +277,14 @@ const EmojiPicker = {
|
|||||||
.map(([_, v]) => v)
|
.map(([_, v]) => v)
|
||||||
.concat(this.unicodeEmojiGroups)
|
.concat(this.unicodeEmojiGroups)
|
||||||
},
|
},
|
||||||
filteredEmojiGroups () {
|
|
||||||
return this.allEmojiGroups
|
|
||||||
.map(group => ({
|
|
||||||
...group,
|
|
||||||
emojis: filterByKeyword(group.emojis, trim(this.keyword))
|
|
||||||
}))
|
|
||||||
.filter(group => group.emojis.length > 0)
|
|
||||||
},
|
|
||||||
stickerPickerEnabled () {
|
stickerPickerEnabled () {
|
||||||
return (this.$store.state.instance.stickers || []).length !== 0
|
return (this.$store.state.instance.stickers || []).length !== 0
|
||||||
|
},
|
||||||
|
debouncedHandleKeywordChange () {
|
||||||
|
return debounce(() => {
|
||||||
|
this.waitForDomAndInitializeLazyLoad()
|
||||||
|
this.filteredEmojiGroups = this.getFilteredEmojiGroups()
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user