From 0673511fc246d67356dd656ad81ba401e3179108 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 3 Mar 2021 16:46:53 +0200 Subject: [PATCH 1/2] fix shoutbox header, use custom scroll-to-bottom system, remove vue-chat-scroll, temporarily add chat test hack --- package.json | 1 - src/App.vue | 2 +- src/components/chat_panel/chat_panel.js | 12 ++++++++++++ src/components/chat_panel/chat_panel.vue | 15 ++++++++++----- src/main.js | 2 -- src/modules/chat.js | 19 +++++++++++++++++++ yarn.lock | 4 ---- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 372155df..8dbf2503 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "punycode.js": "^2.1.0", "v-click-outside": "^2.1.1", "vue": "^2.6.11", - "vue-chat-scroll": "^1.2.1", "vue-i18n": "^7.3.2", "vue-router": "^3.0.1", "vue-template-compiler": "^2.6.11", diff --git a/src/App.vue b/src/App.vue index 1a166778..e09ce4c8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -50,7 +50,7 @@ diff --git a/src/components/chat_panel/chat_panel.js b/src/components/chat_panel/chat_panel.js index c3887098..556694ae 100644 --- a/src/components/chat_panel/chat_panel.js +++ b/src/components/chat_panel/chat_panel.js @@ -35,6 +35,18 @@ const chatPanel = { userProfileLink (user) { return generateProfileLink(user.id, user.username, this.$store.state.instance.restrictedNicknames) } + }, + watch: { + messages (newVal) { + const scrollEl = this.$el.querySelector('.chat-window') + if (!scrollEl) return + if (scrollEl.scrollTop + scrollEl.offsetHeight + 20 > scrollEl.scrollHeight) { + this.$nextTick(() => { + if (!scrollEl) return + scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight + }) + } + } } } diff --git a/src/components/chat_panel/chat_panel.vue b/src/components/chat_panel/chat_panel.vue index 7993c94d..8a829115 100644 --- a/src/components/chat_panel/chat_panel.vue +++ b/src/components/chat_panel/chat_panel.vue @@ -10,17 +10,15 @@ @click.stop.prevent="togglePanel" >
- {{ $t('shoutbox.title') }} + {{ $t('shoutbox.title') }}
-
+
{ + id += 1 + return { + text: 'test' + id, + author: { + username: 'test', + avatar: '', + id + } + } + } + + const loop = () => { + store.commit('addMessage', createmsg()) + setTimeout(loop, 3000) + } + loop() + channel.on('new_msg', (msg) => { store.commit('addMessage', msg) }) diff --git a/yarn.lock b/yarn.lock index 6d0095db..80c09312 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8923,10 +8923,6 @@ void-elements@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" -vue-chat-scroll@^1.2.1: - version "1.3.5" - resolved "https://registry.yarnpkg.com/vue-chat-scroll/-/vue-chat-scroll-1.3.5.tgz#a5ee5bae5058f614818a96eac5ee3be4394a2f68" - vue-eslint-parser@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-5.0.0.tgz#00f4e4da94ec974b821a26ff0ed0f7a78402b8a1" From becacf064303f0fceca8def3f1c49248b9d3e5f8 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 3 Mar 2021 16:47:59 +0200 Subject: [PATCH 2/2] remove shoutbox test hacks --- src/App.vue | 2 +- src/modules/chat.js | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/App.vue b/src/App.vue index e09ce4c8..1a166778 100644 --- a/src/App.vue +++ b/src/App.vue @@ -50,7 +50,7 @@
diff --git a/src/modules/chat.js b/src/modules/chat.js index 264ba00b..ffeb272b 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -18,24 +18,6 @@ const chat = { actions: { initializeChat (store, socket) { const channel = socket.channel('chat:public') - let id = 0 - const createmsg = () => { - id += 1 - return { - text: 'test' + id, - author: { - username: 'test', - avatar: '', - id - } - } - } - - const loop = () => { - store.commit('addMessage', createmsg()) - setTimeout(loop, 3000) - } - loop() channel.on('new_msg', (msg) => { store.commit('addMessage', msg)