From 207ab28b926923d8cc765b8a0d686709dcf3cb6c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 10 Jul 2018 15:04:25 +0300 Subject: [PATCH] Some fixes with IntersectionObserver --- client/components/Chat.vue | 34 ++++++++------ client/components/LinkPreview.vue | 75 +++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/client/components/Chat.vue b/client/components/Chat.vue index 09332682..10c586dc 100644 --- a/client/components/Chat.vue +++ b/client/components/Chat.vue @@ -116,7 +116,11 @@ export default { "channel.messages"() { const el = this.$refs.chat; - if (!el || el.scrollHeight - el.scrollTop - el.offsetHeight > 30) { + if (!el) { + return; + } + + if (el.scrollHeight - el.scrollTop - el.offsetHeight > 30) { return; } @@ -126,24 +130,26 @@ export default { }, }, created() { - if (!this.$refs.chat) { - return; - } - - if (window.IntersectionObserver) { - this.historyObserver = new window.IntersectionObserver(loadMoreHistory, { - root: this.$refs.chat, - }); - } - this.$nextTick(() => { + if (!this.$refs.chat) { + return; + } + + if (window.IntersectionObserver) { + this.historyObserver = new window.IntersectionObserver(loadMoreHistory, { + root: this.$refs.chat, + }); + } + this.$refs.chat.scrollTop = this.$refs.chat.scrollHeight; }); }, mounted() { - if (this.historyObserver) { - this.historyObserver.observe(this.$refs.loadMoreButton); - } + this.$nextTick(() => { + if (this.historyObserver) { + this.historyObserver.observe(this.$refs.loadMoreButton); + } + }); }, destroyed() { if (this.historyObserver) { diff --git a/client/components/LinkPreview.vue b/client/components/LinkPreview.vue index 9281cb66..9beaa47d 100644 --- a/client/components/LinkPreview.vue +++ b/client/components/LinkPreview.vue @@ -2,65 +2,104 @@