aboutsummaryrefslogtreecommitdiff
path: root/src/components/lists_new/lists_new.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2022-08-09 21:46:55 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2022-08-09 21:46:55 +0000
commit7773e7de6454a7ecd79b695ba27cccabeaca184e (patch)
treef14fc29167d7b2a21264351236f1721dd0794456 /src/components/lists_new/lists_new.js
parent2867c696293a96375f60898e10d7a702f60855c5 (diff)
parent891fbf996d7ddd415d99ea9065d54b0f493b5422 (diff)
Merge branch 'lists-implementation' into 'develop'
Add lists support See merge request pleroma/pleroma-fe!1584
Diffstat (limited to 'src/components/lists_new/lists_new.js')
-rw-r--r--src/components/lists_new/lists_new.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/components/lists_new/lists_new.js b/src/components/lists_new/lists_new.js
new file mode 100644
index 00000000..63dc28ad
--- /dev/null
+++ b/src/components/lists_new/lists_new.js
@@ -0,0 +1,79 @@
+import { mapState, mapGetters } from 'vuex'
+import BasicUserCard from '../basic_user_card/basic_user_card.vue'
+import UserAvatar from '../user_avatar/user_avatar.vue'
+import ListsUserSearch from '../lists_user_search/lists_user_search.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: []
+ }
+ },
+ computed: {
+ users () {
+ return this.userIds.map(userId => this.findUser(userId))
+ },
+ selectedUsers () {
+ return this.selectedUserIds.map(userId => this.findUser(userId))
+ },
+ ...mapState({
+ currentUser: state => state.users.currentUser
+ }),
+ ...mapGetters(['findUser'])
+ },
+ methods: {
+ goBack () {
+ this.$emit('cancel')
+ },
+ 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
+ },
+ createList () {
+ // the API has two different endpoints for "creating a list with a name"
+ // and "updating the accounts on the list".
+ this.$store.dispatch('createList', { title: this.title })
+ .then((list) => {
+ this.$store.dispatch('setListAccounts', { id: list.id, accountIds: this.selectedUserIds })
+ this.$router.push({ name: 'lists-timeline', params: { id: list.id } })
+ })
+ }
+ }
+}
+
+export default ListsNew