logo

pleroma-fe

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

lists_edit.js (4356B)


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