aboutsummaryrefslogtreecommitdiff
path: root/src/components/emoji_picker/emoji_picker.js
diff options
context:
space:
mode:
authorTusooa Zhu <tusooa@kazv.moe>2021-10-08 15:09:24 -0400
committerTusooa Zhu <tusooa@kazv.moe>2022-09-18 13:19:52 -0400
commit06a636db3732ce2808c54d3b74eb4aabd866dbf6 (patch)
treee3d52baf059a838547aa127617fd16353ac5c357 /src/components/emoji_picker/emoji_picker.js
parent9aeffd7634e049123d3ffc8addf9c223652b0bbb (diff)
Lazy-load emoji picker in post form
When clicking the reply button, we used to load the whole emoji picker. This causes a considerable delay even if the user is not going to use the emoji picker. Now the content of the emoji picker is loaded only after the user has explicitly opened the emoji picker. Ref: grouped-emoji-picker
Diffstat (limited to 'src/components/emoji_picker/emoji_picker.js')
-rw-r--r--src/components/emoji_picker/emoji_picker.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js
index 5b90c31e..8b4f302f 100644
--- a/src/components/emoji_picker/emoji_picker.js
+++ b/src/components/emoji_picker/emoji_picker.js
@@ -39,6 +39,10 @@ const EmojiPicker = {
required: false,
type: Boolean,
default: false
+ },
+ showing: {
+ required: true,
+ type: Boolean
}
},
data () {
@@ -48,7 +52,9 @@ const EmojiPicker = {
showingStickers: false,
groupsScrolledClass: 'scrolled-top',
keepOpen: false,
- customEmojiTimeout: null
+ customEmojiTimeout: null,
+ // Lazy-load only after the first time `showing` becomes true.
+ contentLoaded: false
}
},
components: {
@@ -115,6 +121,9 @@ const EmojiPicker = {
this.$lozad = lozad('img', {})
this.$lozad.observe()
},
+ waitForDomAndInitializeLazyLoad() {
+ this.$nextTick(() => this.initializeLazyLoad())
+ },
destroyLazyLoad () {
if (this.$lozad) {
if (this.$lozad.observer) {
@@ -129,18 +138,23 @@ const EmojiPicker = {
watch: {
keyword () {
this.onScroll()
- // Wait for the dom to change
- this.$nextTick(() => this.initializeLazyLoad())
+ this.waitForDomAndInitializeLazyLoad()
},
allCustomGroups () {
- this.$nextTick(() => this.initializeLazyLoad())
+ this.waitForDomAndInitializeLazyLoad()
+ },
+ showing (val) {
+ if (val) {
+ this.contentLoaded = true
+ this.waitForDomAndInitializeLazyLoad()
+ }
}
},
mounted () {
if (this.defaultGroup) {
this.highlight(this.defaultGroup)
}
- this.initializeLazyLoad()
+ this.waitForDomAndInitializeLazyLoad()
},
destroyed () {
this.destroyLazyLoad()