Merge branch 'emoji-optimizations' into shigusegubu

* emoji-optimizations:
  moved emoji fetching from user to instance since it's its state anyway
  always preload first batch of emoji to avoid unnecessary UI jumps
This commit is contained in:
Henry Jameson 2019-10-09 22:51:02 +03:00
commit 203f12d521
3 changed files with 80 additions and 58 deletions

View file

@ -24,9 +24,10 @@ const EmojiPicker = {
showingStickers: false,
groupsScrolledClass: 'scrolled-top',
keepOpen: false,
customEmojiBuffer: [],
customEmojiBuffer: (this.$store.state.instance.customEmoji || [])
.slice(0, LOAD_EMOJI_BY),
customEmojiTimeout: null,
customEmojiCounter: 0,
customEmojiCounter: LOAD_EMOJI_BY,
customEmojiLoadAllConfirmed: false
}
},
@ -89,13 +90,23 @@ const EmojiPicker = {
this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL)
this.customEmojiCounter += LOAD_EMOJI_BY
},
startEmojiLoad () {
startEmojiLoad (forceUpdate = false) {
const bufferSize = this.customEmojiBuffer.length
const bufferPrefilledSane = bufferSize === LOAD_EMOJI_SANE_AMOUNT && !this.customEmojiLoadAllConfirmed
const bufferPrefilledAll = bufferSize === this.filteredEmoji.length
if (!forceUpdate || bufferPrefilledSane || bufferPrefilledAll) {
return
}
if (this.customEmojiTimeout) {
window.clearTimeout(this.customEmojiTimeout)
}
set(this, 'customEmojiBuffer', [])
this.customEmojiCounter = 0
set(
this,
'customEmojiBuffer',
this.filteredEmoji.slice(0, LOAD_EMOJI_BY)
)
this.customEmojiCounter = LOAD_EMOJI_BY
this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL)
},
continueEmojiLoad () {
@ -116,8 +127,9 @@ const EmojiPicker = {
},
watch: {
keyword () {
this.customEmojiLoadAllConfirmed = false
this.scrolledGroup()
this.startEmojiLoad()
this.startEmojiLoad(true)
}
},
computed: {