pleroma-fe/src/components/shout_panel/shout_panel.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

import { useInstanceStore } from 'src/stores/instance.js'
2025-02-03 13:02:14 +02:00
import { useShoutStore } from 'src/stores/shout'
2026-01-29 20:40:00 +02:00
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faBullhorn, faTimes } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faBullhorn, faTimes)
2018-12-13 05:00:01 +03:00
const shoutPanel = {
2022-07-31 12:35:48 +03:00
props: ['floating'],
2026-01-06 16:22:52 +02:00
data() {
2017-12-05 11:02:41 +01:00
return {
currentMessage: '',
channel: null,
2026-01-06 16:22:52 +02:00
collapsed: true,
2017-12-05 11:02:41 +01:00
}
},
2017-12-05 11:47:10 +01:00
computed: {
2026-01-06 16:22:52 +02:00
messages() {
2023-04-04 21:17:54 -06:00
return useShoutStore().messages
2026-01-06 16:22:52 +02:00
},
2017-12-05 11:02:41 +01:00
},
methods: {
2026-01-06 16:22:52 +02:00
submit(message) {
2023-04-04 21:17:54 -06:00
useShoutStore().channel.push('new_msg', { text: message }, 10000)
2017-12-05 11:49:40 +01:00
this.currentMessage = ''
},
2026-01-06 16:22:52 +02:00
togglePanel() {
this.collapsed = !this.collapsed
2018-12-17 02:52:27 +03:00
},
2026-01-06 16:22:52 +02:00
userProfileLink(user) {
return generateProfileLink(
user.id,
user.username,
useInstanceStore().restrictedNicknames,
2026-01-06 16:22:52 +02:00
)
},
},
watch: {
2026-01-06 16:22:52 +02:00
messages() {
const scrollEl = this.$el.querySelector('.chat-window')
if (!scrollEl) return
2026-01-06 16:22:52 +02:00
if (
scrollEl.scrollTop + scrollEl.offsetHeight + 20 >
scrollEl.scrollHeight
) {
this.$nextTick(() => {
if (!scrollEl) return
scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight
})
}
2026-01-06 16:22:52 +02:00
},
},
2017-12-05 11:02:41 +01:00
}
export default shoutPanel