logo

pleroma-fe

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

user_list_menu.js (2980B)


  1. import { library } from '@fortawesome/fontawesome-svg-core'
  2. import { faChevronRight } from '@fortawesome/free-solid-svg-icons'
  3. import { mapState } from 'vuex'
  4. import DialogModal from '../dialog_modal/dialog_modal.vue'
  5. import Popover from '../popover/popover.vue'
  6. library.add(faChevronRight)
  7. const UserListMenu = {
  8. props: [
  9. 'user'
  10. ],
  11. data () {
  12. return {}
  13. },
  14. components: {
  15. DialogModal,
  16. Popover
  17. },
  18. created () {
  19. this.$store.dispatch('fetchUserInLists', this.user.id)
  20. },
  21. computed: {
  22. ...mapState({
  23. allLists: state => state.lists.allLists
  24. }),
  25. inListsSet () {
  26. return new Set(this.user.inLists.map(x => x.id))
  27. },
  28. lists () {
  29. if (!this.user.inLists) return []
  30. return this.allLists.map(list => ({
  31. ...list,
  32. inList: this.inListsSet.has(list.id)
  33. }))
  34. },
  35. triggerAttrs () {
  36. return {
  37. class: 'menu-item dropdown-item -has-submenu'
  38. }
  39. }
  40. },
  41. methods: {
  42. toggleList (listId) {
  43. if (this.inListsSet.has(listId)) {
  44. this.$store.dispatch('removeListAccount', { accountId: this.user.id, listId }).then((response) => {
  45. if (!response.ok) { return }
  46. this.$store.dispatch('fetchUserInLists', this.user.id)
  47. })
  48. } else {
  49. this.$store.dispatch('addListAccount', { accountId: this.user.id, listId }).then((response) => {
  50. if (!response.ok) { return }
  51. this.$store.dispatch('fetchUserInLists', this.user.id)
  52. })
  53. }
  54. },
  55. toggleRight (right) {
  56. const store = this.$store
  57. if (this.user.rights[right]) {
  58. store.state.api.backendInteractor.deleteRight({ user: this.user, right }).then(response => {
  59. if (!response.ok) { return }
  60. store.commit('updateRight', { user: this.user, right, value: false })
  61. })
  62. } else {
  63. store.state.api.backendInteractor.addRight({ user: this.user, right }).then(response => {
  64. if (!response.ok) { return }
  65. store.commit('updateRight', { user: this.user, right, value: true })
  66. })
  67. }
  68. },
  69. toggleActivationStatus () {
  70. this.$store.dispatch('toggleActivationStatus', { user: this.user })
  71. },
  72. deleteUserDialog (show) {
  73. this.showDeleteUserDialog = show
  74. },
  75. deleteUser () {
  76. const store = this.$store
  77. const user = this.user
  78. const { id, name } = user
  79. store.state.api.backendInteractor.deleteUser({ user })
  80. .then(e => {
  81. this.$store.dispatch('markStatusesAsDeleted', status => user.id === status.user.id)
  82. const isProfile = this.$route.name === 'external-user-profile' || this.$route.name === 'user-profile'
  83. const isTargetUser = this.$route.params.name === name || this.$route.params.id === id
  84. if (isProfile && isTargetUser) {
  85. window.history.back()
  86. }
  87. })
  88. },
  89. setToggled (value) {
  90. this.toggled = value
  91. }
  92. }
  93. }
  94. export default UserListMenu