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


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