fix shoutbox header, use custom scroll-to-bottom system, remove vue-chat-scroll, temporarily add chat test hack

This commit is contained in:
Shpuld Shpuldson 2021-03-03 16:46:53 +02:00
parent 30057a4944
commit 0673511fc2
7 changed files with 42 additions and 13 deletions

View file

@ -50,7 +50,7 @@
<media-modal />
</div>
<chat-panel
v-if="currentUser && chat"
v-if="currentUser"
:floating="true"
class="floating-chat mobile-hidden"
/>

View file

@ -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
})
}
}
}
}

View file

@ -10,17 +10,15 @@
@click.stop.prevent="togglePanel"
>
<div class="title">
<span>{{ $t('shoutbox.title') }}</span>
{{ $t('shoutbox.title') }}
<FAIcon
v-if="floating"
icon="times"
class="close-icon"
/>
</div>
</div>
<div
v-chat-scroll
class="chat-window"
>
<div class="chat-window">
<div
v-for="message in messages"
:key="message.id"
@ -94,6 +92,13 @@
.icon {
color: $fallback--text;
color: var(--text, $fallback--text);
margin-right: 0.5em;
}
.title {
display: flex;
justify-content: space-between;
align-items: center;
}
}

View file

@ -28,7 +28,6 @@ import pushNotifications from './lib/push_notifications_plugin.js'
import messages from './i18n/messages.js'
import VueChatScroll from 'vue-chat-scroll'
import VueClickOutside from 'v-click-outside'
import PortalVue from 'portal-vue'
import VBodyScrollLock from './directives/body_scroll_lock'
@ -42,7 +41,6 @@ const currentLocale = (window.navigator.language || 'en').split('-')[0]
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(VueI18n)
Vue.use(VueChatScroll)
Vue.use(VueClickOutside)
Vue.use(PortalVue)
Vue.use(VBodyScrollLock)

View file

@ -18,6 +18,25 @@ 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)
})