logo

pleroma-fe

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

user_list_menu.js (2874B)


  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. },
  36. methods: {
  37. toggleList (listId) {
  38. if (this.inListsSet.has(listId)) {
  39. this.$store.dispatch('removeListAccount', { accountId: this.user.id, listId }).then((response) => {
  40. if (!response.ok) { return }
  41. this.$store.dispatch('fetchUserInLists', this.user.id)
  42. })
  43. } else {
  44. this.$store.dispatch('addListAccount', { accountId: this.user.id, listId }).then((response) => {
  45. if (!response.ok) { return }
  46. this.$store.dispatch('fetchUserInLists', this.user.id)
  47. })
  48. }
  49. },
  50. toggleRight (right) {
  51. const store = this.$store
  52. if (this.user.rights[right]) {
  53. store.state.api.backendInteractor.deleteRight({ user: this.user, right }).then(response => {
  54. if (!response.ok) { return }
  55. store.commit('updateRight', { user: this.user, right, value: false })
  56. })
  57. } else {
  58. store.state.api.backendInteractor.addRight({ user: this.user, right }).then(response => {
  59. if (!response.ok) { return }
  60. store.commit('updateRight', { user: this.user, right, value: true })
  61. })
  62. }
  63. },
  64. toggleActivationStatus () {
  65. this.$store.dispatch('toggleActivationStatus', { user: this.user })
  66. },
  67. deleteUserDialog (show) {
  68. this.showDeleteUserDialog = show
  69. },
  70. deleteUser () {
  71. const store = this.$store
  72. const user = this.user
  73. const { id, name } = user
  74. store.state.api.backendInteractor.deleteUser({ user })
  75. .then(e => {
  76. this.$store.dispatch('markStatusesAsDeleted', status => user.id === status.user.id)
  77. const isProfile = this.$route.name === 'external-user-profile' || this.$route.name === 'user-profile'
  78. const isTargetUser = this.$route.params.name === name || this.$route.params.id === id
  79. if (isProfile && isTargetUser) {
  80. window.history.back()
  81. }
  82. })
  83. },
  84. setToggled (value) {
  85. this.toggled = value
  86. }
  87. }
  88. }
  89. export default UserListMenu