logo

pleroma-fe

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

lists_edit.js (4256B)


  1. import { mapState, mapGetters } from 'vuex'
  2. import BasicUserCard from '../basic_user_card/basic_user_card.vue'
  3. import ListsUserSearch from '../lists_user_search/lists_user_search.vue'
  4. import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
  5. import UserAvatar from '../user_avatar/user_avatar.vue'
  6. import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'
  7. import { library } from '@fortawesome/fontawesome-svg-core'
  8. import {
  9. faSearch,
  10. faChevronLeft
  11. } from '@fortawesome/free-solid-svg-icons'
  12. library.add(
  13. faSearch,
  14. faChevronLeft
  15. )
  16. const ListsNew = {
  17. components: {
  18. BasicUserCard,
  19. UserAvatar,
  20. ListsUserSearch,
  21. TabSwitcher,
  22. PanelLoading
  23. },
  24. data () {
  25. return {
  26. title: '',
  27. titleDraft: '',
  28. membersUserIds: [],
  29. removedUserIds: new Set([]), // users we added for members, to undo
  30. searchUserIds: [],
  31. addedUserIds: new Set([]), // users we added from search, to undo
  32. searchLoading: false,
  33. reallyDelete: false
  34. }
  35. },
  36. created () {
  37. if (!this.id) return
  38. this.$store.dispatch('fetchList', { listId: this.id })
  39. .then(() => {
  40. this.title = this.findListTitle(this.id)
  41. this.titleDraft = this.title
  42. })
  43. this.$store.dispatch('fetchListAccounts', { listId: this.id })
  44. .then(() => {
  45. this.membersUserIds = this.findListAccounts(this.id)
  46. this.membersUserIds.forEach(userId => {
  47. this.$store.dispatch('fetchUserIfMissing', userId)
  48. })
  49. })
  50. },
  51. computed: {
  52. id () {
  53. return this.$route.params.id
  54. },
  55. membersUsers () {
  56. return [...this.membersUserIds, ...this.addedUserIds]
  57. .map(userId => this.findUser(userId)).filter(user => user)
  58. },
  59. searchUsers () {
  60. return this.searchUserIds.map(userId => this.findUser(userId)).filter(user => user)
  61. },
  62. ...mapState({
  63. currentUser: state => state.users.currentUser
  64. }),
  65. ...mapGetters(['findUser', 'findListTitle', 'findListAccounts'])
  66. },
  67. methods: {
  68. onInput () {
  69. this.search(this.query)
  70. },
  71. toggleRemoveMember (user) {
  72. if (this.removedUserIds.has(user.id)) {
  73. this.id && this.addUser(user)
  74. this.removedUserIds.delete(user.id)
  75. } else {
  76. this.id && this.removeUser(user.id)
  77. this.removedUserIds.add(user.id)
  78. }
  79. },
  80. toggleAddFromSearch (user) {
  81. if (this.addedUserIds.has(user.id)) {
  82. this.id && this.removeUser(user.id)
  83. this.addedUserIds.delete(user.id)
  84. } else {
  85. this.id && this.addUser(user)
  86. this.addedUserIds.add(user.id)
  87. }
  88. },
  89. isRemoved (user) {
  90. return this.removedUserIds.has(user.id)
  91. },
  92. isAdded (user) {
  93. return this.addedUserIds.has(user.id)
  94. },
  95. addUser (user) {
  96. this.$store.dispatch('addListAccount', { accountId: user.id, listId: this.id })
  97. },
  98. removeUser (userId) {
  99. this.$store.dispatch('removeListAccount', { accountId: userId, listId: this.id })
  100. },
  101. onSearchLoading (results) {
  102. this.searchLoading = true
  103. },
  104. onSearchLoadingDone (results) {
  105. this.searchLoading = false
  106. },
  107. onSearchResults (results) {
  108. this.searchLoading = false
  109. this.searchUserIds = results
  110. },
  111. updateListTitle () {
  112. this.$store.dispatch('setList', { listId: this.id, title: this.titleDraft })
  113. .then(() => {
  114. this.title = this.findListTitle(this.id)
  115. })
  116. },
  117. createList () {
  118. this.$store.dispatch('createList', { title: this.titleDraft })
  119. .then((list) => {
  120. return this
  121. .$store
  122. .dispatch('setListAccounts', { listId: list.id, accountIds: [...this.addedUserIds] })
  123. .then(() => list.id)
  124. })
  125. .then((listId) => {
  126. this.$router.push({ name: 'lists-timeline', params: { id: listId } })
  127. })
  128. .catch((e) => {
  129. this.$store.dispatch('pushGlobalNotice', {
  130. messageKey: 'lists.error',
  131. messageArgs: [e.message],
  132. level: 'error'
  133. })
  134. })
  135. },
  136. deleteList () {
  137. this.$store.dispatch('deleteList', { listId: this.id })
  138. this.$router.push({ name: 'lists' })
  139. }
  140. }
  141. }
  142. export default ListsNew