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

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-12-13 02:00:01 +00:00
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { library } from '@fortawesome/fontawesome-svg-core'
2020-10-20 18:18:23 +00:00
import {
faBullhorn,
faTimes
} from '@fortawesome/free-solid-svg-icons'
library.add(
2020-10-20 18:18:23 +00:00
faBullhorn,
faTimes
)
2018-12-13 02:00:01 +00:00
const shoutPanel = {
props: [ 'floating' ],
2017-12-05 10:02:41 +00:00
data () {
return {
currentMessage: '',
channel: null,
2018-04-24 07:48:30 +00:00
collapsed: true
2017-12-05 10:02:41 +00:00
}
},
2017-12-05 10:47:10 +00:00
computed: {
messages () {
return this.$store.state.shout.messages
2017-12-05 10:47:10 +00:00
}
2017-12-05 10:02:41 +00:00
},
methods: {
2017-12-05 10:49:40 +00:00
submit (message) {
this.$store.state.shout.channel.push('new_msg', { text: message }, 10000)
2017-12-05 10:49:40 +00:00
this.currentMessage = ''
},
togglePanel () {
this.collapsed = !this.collapsed
2018-12-16 23:52:27 +00:00
},
userProfileLink (user) {
return generateProfileLink(user.id, user.username, this.$store.state.instance.restrictedNicknames)
2017-12-05 10:02:41 +00:00
}
},
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
})
}
}
2017-12-05 10:02:41 +00:00
}
}
export default shoutPanel