aboutsummaryrefslogtreecommitdiff
path: root/src/components/emoji_reactions/emoji_reactions.js
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2020-06-17 11:23:32 +0300
committerShpuld Shpuldson <shp@cock.li>2020-06-17 11:23:32 +0300
commitf8cf92a01f952f344ee4c3b7df153b2ffdb7988f (patch)
treed1f20bc99722d2b94aeef772acd59083145d71ac /src/components/emoji_reactions/emoji_reactions.js
parent064b59812c715d60526727d42c124375a2bc89d5 (diff)
parent57626c125d0477716a638854c4243ee0fde96923 (diff)
Merge branch 'develop' into kPherox/pleroma-fe-iss-149/profile-fields-display
Diffstat (limited to 'src/components/emoji_reactions/emoji_reactions.js')
-rw-r--r--src/components/emoji_reactions/emoji_reactions.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/components/emoji_reactions/emoji_reactions.js b/src/components/emoji_reactions/emoji_reactions.js
new file mode 100644
index 00000000..ae7f53be
--- /dev/null
+++ b/src/components/emoji_reactions/emoji_reactions.js
@@ -0,0 +1,69 @@
+import UserAvatar from '../user_avatar/user_avatar.vue'
+import Popover from '../popover/popover.vue'
+
+const EMOJI_REACTION_COUNT_CUTOFF = 12
+
+const EmojiReactions = {
+ name: 'EmojiReactions',
+ components: {
+ UserAvatar,
+ Popover
+ },
+ props: ['status'],
+ data: () => ({
+ showAll: false
+ }),
+ computed: {
+ tooManyReactions () {
+ return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF
+ },
+ 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
+ }
+ },
+ methods: {
+ toggleShowAll () {
+ this.showAll = !this.showAll
+ },
+ 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)
+ }
+ },
+ 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
+
+ if (this.reactedWith(emoji)) {
+ this.unreact(emoji)
+ } else {
+ this.reactWith(emoji)
+ }
+ }
+ }
+}
+
+export default EmojiReactions