From 91386b68c044d94013c9fab8f6f44d41f5bf705f Mon Sep 17 00:00:00 2001 From: Troplo Date: Sat, 30 Jul 2022 18:01:18 +1000 Subject: [PATCH] Update CommunicationsChat.vue --- .../Communications/CommunicationsChat.vue | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/frontend/src/views/Communications/CommunicationsChat.vue b/frontend/src/views/Communications/CommunicationsChat.vue index b621043..eec6eaa 100644 --- a/frontend/src/views/Communications/CommunicationsChat.vue +++ b/frontend/src/views/Communications/CommunicationsChat.vue @@ -1115,32 +1115,34 @@ export default { this.focusInput() }, autoScroll(smooth = false) { - if (!this.avoidAutoScroll) { - try { - const lastIndex = this.messages.length - 1 - const lastMessage = document.querySelector(`#message-${lastIndex}`) - if (smooth) { - lastMessage.scrollIntoView({ - behavior: "smooth", - block: "nearest", - inline: "start" - }) - } else { - lastMessage.scrollIntoView() - } - this.autoScrollRetry = 0 - } catch (e) { - console.log("Could not auto scroll, retrying...") - if (this.autoScrollRetry < 20) { - setTimeout(() => { - this.autoScroll() - }, 50) - this.autoScrollRetry++ - } else { - console.log("Could not auto scroll, retry limit reached") + this.$nextTick(() => { + if (!this.avoidAutoScroll) { + try { + const lastIndex = this.messages.length - 1 + const lastMessage = document.querySelector(`#message-${lastIndex}`) + if (smooth) { + lastMessage.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "start" + }) + } else { + lastMessage.scrollIntoView() + } + this.autoScrollRetry = 0 + } catch (e) { + console.log("Could not auto scroll, retrying...") + if (this.autoScrollRetry < 20) { + setTimeout(() => { + this.autoScroll() + }, 50) + this.autoScrollRetry++ + } else { + console.log("Could not auto scroll, retry limit reached") + } } } - } + }) }, getMessages() { this.loadingMessages = true