aboutsummaryrefslogtreecommitdiff
path: root/src/components/lists_edit/lists_edit.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2022-08-22 22:29:13 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2022-08-22 22:29:13 +0000
commit272b748f26d0bb7b9f3a00336a908d507f4169bc (patch)
treee0d102a21b4a62aab390617b2b217341cb969e3d /src/components/lists_edit/lists_edit.js
parenta403f93b478eec67d779400b1fcfdc006bb787da (diff)
parent88a3cf8705f925c31b5fad67d0fb709a51447156 (diff)
Merge branch 'develop' into 'allow-opening-profile-in-user-popover'
# Conflicts: # src/components/settings_modal/tabs/general_tab.vue
Diffstat (limited to 'src/components/lists_edit/lists_edit.js')
-rw-r--r--src/components/lists_edit/lists_edit.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/components/lists_edit/lists_edit.js b/src/components/lists_edit/lists_edit.js
new file mode 100644
index 00000000..a68bb589
--- /dev/null
+++ b/src/components/lists_edit/lists_edit.js
@@ -0,0 +1,91 @@
+import { mapState, mapGetters } from 'vuex'
+import BasicUserCard from '../basic_user_card/basic_user_card.vue'
+import ListsUserSearch from '../lists_user_search/lists_user_search.vue'
+import UserAvatar from '../user_avatar/user_avatar.vue'
+import { library } from '@fortawesome/fontawesome-svg-core'
+import {
+ faSearch,
+ faChevronLeft
+} from '@fortawesome/free-solid-svg-icons'
+
+library.add(
+ faSearch,
+ faChevronLeft
+)
+
+const ListsNew = {
+ components: {
+ BasicUserCard,
+ UserAvatar,
+ ListsUserSearch
+ },
+ data () {
+ return {
+ title: '',
+ userIds: [],
+ selectedUserIds: []
+ }
+ },
+ created () {
+ this.$store.dispatch('fetchList', { id: this.id })
+ .then(() => { this.title = this.findListTitle(this.id) })
+ this.$store.dispatch('fetchListAccounts', { id: this.id })
+ .then(() => {
+ this.selectedUserIds = this.findListAccounts(this.id)
+ this.selectedUserIds.forEach(userId => {
+ this.$store.dispatch('fetchUserIfMissing', userId)
+ })
+ })
+ },
+ computed: {
+ id () {
+ return this.$route.params.id
+ },
+ users () {
+ return this.userIds.map(userId => this.findUser(userId))
+ },
+ selectedUsers () {
+ return this.selectedUserIds.map(userId => this.findUser(userId)).filter(user => user)
+ },
+ ...mapState({
+ currentUser: state => state.users.currentUser
+ }),
+ ...mapGetters(['findUser', 'findListTitle', 'findListAccounts'])
+ },
+ methods: {
+ onInput () {
+ this.search(this.query)
+ },
+ selectUser (user) {
+ if (this.selectedUserIds.includes(user.id)) {
+ this.removeUser(user.id)
+ } else {
+ this.addUser(user)
+ }
+ },
+ isSelected (user) {
+ return this.selectedUserIds.includes(user.id)
+ },
+ addUser (user) {
+ this.selectedUserIds.push(user.id)
+ },
+ removeUser (userId) {
+ this.selectedUserIds = this.selectedUserIds.filter(id => id !== userId)
+ },
+ onResults (results) {
+ this.userIds = results
+ },
+ updateList () {
+ this.$store.dispatch('setList', { id: this.id, title: this.title })
+ this.$store.dispatch('setListAccounts', { id: this.id, accountIds: this.selectedUserIds })
+
+ this.$router.push({ name: 'lists-timeline', params: { id: this.id } })
+ },
+ deleteList () {
+ this.$store.dispatch('deleteList', { id: this.id })
+ this.$router.push({ name: 'lists' })
+ }
+ }
+}
+
+export default ListsNew