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

70 lines
1.8 KiB
JavaScript
Raw Normal View History

import UserAvatar from '../user_avatar/user_avatar.vue'
2020-02-28 16:39:47 +00:00
import Popover from '../popover/popover.vue'
const EMOJI_REACTION_COUNT_CUTOFF = 12
2020-01-14 08:06:14 +00:00
const EmojiReactions = {
name: 'EmojiReactions',
components: {
2020-02-28 16:39:47 +00:00
UserAvatar,
Popover
},
2020-01-14 08:06:14 +00:00
props: ['status'],
data: () => ({
2020-02-28 16:39:47 +00:00
showAll: false
}),
2020-01-14 08:06:14 +00:00
computed: {
tooManyReactions () {
return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF
},
2020-01-14 08:06:14 +00:00
emojiReactions () {
return this.showAll
? this.status.emoji_reactions
: this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF)
},
showMoreString () {
return `+${this.status.emoji_reactions.length - EMOJI_REACTION_COUNT_CUTOFF}`
},
accountsForEmoji () {
return this.status.emoji_reactions.reduce((acc, reaction) => {
acc[reaction.name] = reaction.accounts || []
return acc
}, {})
},
loggedIn () {
return !!this.$store.state.users.currentUser
2020-01-14 08:06:14 +00:00
}
},
methods: {
toggleShowAll () {
this.showAll = !this.showAll
},
2020-01-14 08:06:14 +00:00
reactedWith (emoji) {
return this.status.emoji_reactions.find(r => r.name === emoji).me
},
fetchEmojiReactionsByIfMissing () {
const hasNoAccounts = this.status.emoji_reactions.find(r => !r.accounts)
if (hasNoAccounts) {
this.$store.dispatch('fetchEmojiReactionsBy', this.status.id)
}
2020-01-14 08:06:14 +00:00
},
reactWith (emoji) {
this.$store.dispatch('reactWithEmoji', { id: this.status.id, emoji })
},
unreact (emoji) {
this.$store.dispatch('unreactWithEmoji', { id: this.status.id, emoji })
},
emojiOnClick (emoji, event) {
if (!this.loggedIn) return
2020-01-14 08:06:14 +00:00
if (this.reactedWith(emoji)) {
this.unreact(emoji)
} else {
this.reactWith(emoji)
}
}
}
}
export default EmojiReactions