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 (4017B)


  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. funcArg () {
  50. return {
  51. status: this.status,
  52. replying: this.replying,
  53. emit: this.$emit,
  54. dispatch: this.$store.dispatch,
  55. state: this.$store.state,
  56. getters: this.$store.getters,
  57. router: this.$router,
  58. currentUser: this.currentUser,
  59. loggedIn: !!this.currentUser
  60. }
  61. },
  62. triggerAttrs () {
  63. return {
  64. title: this.$t('status.more_actions'),
  65. 'aria-controls': `popup-menu-${this.randomSeed}`,
  66. 'aria-haspopup': 'menu'
  67. }
  68. }
  69. },
  70. methods: {
  71. doAction (button) {
  72. if (button.confirm?.(this.funcArg)) {
  73. // TODO move to action_button
  74. this.currentConfirmTitle = this.$t(button.confirmStrings(this.funcArg).title)
  75. this.currentConfirmOkText = this.$t(button.confirmStrings(this.funcArg).confirm)
  76. this.currentConfirmCancelText = this.$t(button.confirmStrings(this.funcArg).cancel)
  77. this.currentConfirmBody = this.$t(button.confirmStrings(this.funcArg).body)
  78. this.currentConfirmAction = () => {
  79. this.showingConfirmDialog = false
  80. this.doActionReal(button)
  81. }
  82. this.showingConfirmDialog = true
  83. } else {
  84. this.doActionReal(button)
  85. }
  86. },
  87. doActionReal (button) {
  88. button.action(this.funcArg)
  89. .then(() => this.$emit('onSuccess'))
  90. .catch(err => this.$emit('onError', err.error.error))
  91. },
  92. onExtraClose () {
  93. this.showPin = false
  94. },
  95. isPinned (button) {
  96. return this.pinnedItems.has(button.name)
  97. },
  98. unpin (button) {
  99. this.$store.commit('removeCollectionPreference', { path: 'collections.pinnedStatusActions', value: button.name })
  100. this.$store.dispatch('pushServerSideStorage')
  101. },
  102. pin (button) {
  103. this.$store.commit('addCollectionPreference', { path: 'collections.pinnedStatusActions', value: button.name })
  104. this.$store.dispatch('pushServerSideStorage')
  105. },
  106. getComponent (button) {
  107. if (!this.$store.state.users.currentUser && button.anonLink) {
  108. return 'a'
  109. } else if (button.action == null && button.link != null) {
  110. return 'a'
  111. } else {
  112. return 'button'
  113. }
  114. },
  115. getClass (button) {
  116. return {
  117. [button.name + '-button']: true,
  118. disabled: button.interactive ? !button.interactive(this.funcArg) : false,
  119. '-pin-edit': this.showPin,
  120. '-dropdown': button.dropdown?.(),
  121. '-active': button.active?.(this.funcArg)
  122. }
  123. }
  124. }
  125. }
  126. export default StatusActionButtons