logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

emoji_reactions.js (2614B)


  1. import UserAvatar from '../user_avatar/user_avatar.vue'
  2. import UserListPopover from '../user_list_popover/user_list_popover.vue'
  3. import { library } from '@fortawesome/fontawesome-svg-core'
  4. import {
  5. faPlus,
  6. faMinus,
  7. faCheck
  8. } from '@fortawesome/free-solid-svg-icons'
  9. library.add(
  10. faPlus,
  11. faMinus,
  12. faCheck
  13. )
  14. const EMOJI_REACTION_COUNT_CUTOFF = 12
  15. const EmojiReactions = {
  16. name: 'EmojiReactions',
  17. components: {
  18. UserAvatar,
  19. UserListPopover
  20. },
  21. props: ['status'],
  22. data: () => ({
  23. showAll: false
  24. }),
  25. computed: {
  26. tooManyReactions () {
  27. return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF
  28. },
  29. emojiReactions () {
  30. return this.showAll
  31. ? this.status.emoji_reactions
  32. : this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF)
  33. },
  34. showMoreString () {
  35. return `+${this.status.emoji_reactions.length - EMOJI_REACTION_COUNT_CUTOFF}`
  36. },
  37. accountsForEmoji () {
  38. return this.status.emoji_reactions.reduce((acc, reaction) => {
  39. acc[reaction.name] = reaction.accounts || []
  40. return acc
  41. }, {})
  42. },
  43. loggedIn () {
  44. return !!this.$store.state.users.currentUser
  45. },
  46. remoteInteractionLink () {
  47. return this.$store.getters.remoteInteractionLink({ statusId: this.status.id })
  48. }
  49. },
  50. methods: {
  51. toggleShowAll () {
  52. this.showAll = !this.showAll
  53. },
  54. reactedWith (emoji) {
  55. return this.status.emoji_reactions.find(r => r.name === emoji).me
  56. },
  57. async fetchEmojiReactionsByIfMissing () {
  58. const hasNoAccounts = this.status.emoji_reactions.find(r => !r.accounts)
  59. if (hasNoAccounts) {
  60. return await this.$store.dispatch('fetchEmojiReactionsBy', this.status.id)
  61. }
  62. },
  63. reactWith (emoji) {
  64. this.$store.dispatch('reactWithEmoji', { id: this.status.id, emoji })
  65. },
  66. unreact (emoji) {
  67. this.$store.dispatch('unreactWithEmoji', { id: this.status.id, emoji })
  68. },
  69. async emojiOnClick (emoji, event) {
  70. if (!this.loggedIn) return
  71. await this.fetchEmojiReactionsByIfMissing()
  72. if (this.reactedWith(emoji)) {
  73. this.unreact(emoji)
  74. } else {
  75. this.reactWith(emoji)
  76. }
  77. },
  78. counterTriggerAttrs (reaction) {
  79. return {
  80. class: [
  81. 'btn',
  82. 'button-default',
  83. 'emoji-reaction-count-button',
  84. { '-picked-reaction': this.reactedWith(reaction.name) }
  85. ],
  86. 'aria-label': this.$tc('status.reaction_count_label', reaction.count, { num: reaction.count })
  87. }
  88. }
  89. }
  90. }
  91. export default EmojiReactions