logo

pleroma-fe

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

status_action_buttons.js (4167B)


  1. import { mapState } from 'vuex'
  2. import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue'
  3. import ActionButtonContainer from './action_button_container.vue'
  4. import Popover from 'src/components/popover/popover.vue'
  5. import genRandomSeed from 'src/services/random_seed/random_seed.service.js'
  6. import { BUTTONS } from './buttons_definitions.js'
  7. import { library } from '@fortawesome/fontawesome-svg-core'
  8. import {
  9. faEllipsisH
  10. } from '@fortawesome/free-solid-svg-icons'
  11. library.add(
  12. faEllipsisH
  13. )
  14. const StatusActionButtons = {
  15. props: ['status', 'replying'],
  16. emits: ['toggleReplying'],
  17. data () {
  18. return {
  19. showPin: false,
  20. showingConfirmDialog: false,
  21. currentConfirmTitle: '',
  22. currentConfirmOkText: '',
  23. currentConfirmCancelText: '',
  24. currentConfirmAction: () => {},
  25. randomSeed: genRandomSeed()
  26. }
  27. },
  28. components: {
  29. Popover,
  30. ConfirmModal,
  31. ActionButtonContainer
  32. },
  33. computed: {
  34. ...mapState({
  35. pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedStatusActions)
  36. }),
  37. buttons () {
  38. return BUTTONS.filter(x => x.if ? x.if(this.funcArg) : true)
  39. },
  40. quickButtons () {
  41. return this.buttons.filter(x => this.pinnedItems.has(x.name))
  42. },
  43. extraButtons () {
  44. return this.buttons.filter(x => !this.pinnedItems.has(x.name))
  45. },
  46. currentUser () {
  47. return this.$store.state.users.currentUser
  48. },
  49. hideCustomEmoji () {
  50. return !this.$store.state.instance.pleromaCustomEmojiReactionsAvailable
  51. },
  52. funcArg () {
  53. return {
  54. status: this.status,
  55. replying: this.replying,
  56. emit: this.$emit,
  57. dispatch: this.$store.dispatch,
  58. state: this.$store.state,
  59. getters: this.$store.getters,
  60. router: this.$router,
  61. currentUser: this.currentUser,
  62. loggedIn: !!this.currentUser
  63. }
  64. },
  65. triggerAttrs () {
  66. return {
  67. title: this.$t('status.more_actions'),
  68. 'aria-controls': `popup-menu-${this.randomSeed}`,
  69. 'aria-expanded': this.expanded,
  70. 'aria-haspopup': 'menu'
  71. }
  72. }
  73. },
  74. methods: {
  75. doAction (button) {
  76. if (button.confirm?.(this.funcArg)) {
  77. // TODO move to action_button
  78. this.currentConfirmTitle = this.$t(button.confirmStrings(this.funcArg).title)
  79. this.currentConfirmOkText = this.$t(button.confirmStrings(this.funcArg).confirm)
  80. this.currentConfirmCancelText = this.$t(button.confirmStrings(this.funcArg).cancel)
  81. this.currentConfirmBody = this.$t(button.confirmStrings(this.funcArg).body)
  82. this.currentConfirmAction = () => {
  83. this.showingConfirmDialog = false
  84. this.doActionReal(button)
  85. }
  86. this.showingConfirmDialog = true
  87. } else {
  88. this.doActionReal(button)
  89. }
  90. },
  91. doActionReal (button) {
  92. button.action(this.funcArg)
  93. .then(() => this.$emit('onSuccess'))
  94. .catch(err => this.$emit('onError', err.error.error))
  95. },
  96. onExtraClose () {
  97. this.showPin = false
  98. },
  99. isPinned (button) {
  100. return this.pinnedItems.has(button.name)
  101. },
  102. unpin (button) {
  103. this.$store.commit('removeCollectionPreference', { path: 'collections.pinnedStatusActions', value: button.name })
  104. this.$store.dispatch('pushServerSideStorage')
  105. },
  106. pin (button) {
  107. this.$store.commit('addCollectionPreference', { path: 'collections.pinnedStatusActions', value: button.name })
  108. this.$store.dispatch('pushServerSideStorage')
  109. },
  110. getComponent (button) {
  111. if (!this.$store.state.users.currentUser && button.anonLink) {
  112. return 'a'
  113. } else if (button.action == null && button.link != null) {
  114. return 'a'
  115. } else {
  116. return 'button'
  117. }
  118. },
  119. getClass (button) {
  120. return {
  121. [button.name + '-button']: true,
  122. disabled: button.interactive ? !button.interactive(this.funcArg) : false,
  123. '-pin-edit': this.showPin,
  124. '-dropdown': button.dropdown?.(),
  125. '-active': button.active?.(this.funcArg)
  126. }
  127. }
  128. }
  129. }
  130. export default StatusActionButtons