From 171f6f08943dd1d87120df3e4894ddcfd5e1d246 Mon Sep 17 00:00:00 2001 From: Alexander Tumin Date: Sat, 6 Aug 2022 17:26:43 +0300 Subject: Lists implementation --- src/components/lists_new/lists_new.js | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/components/lists_new/lists_new.js (limited to 'src/components/lists_new/lists_new.js') diff --git a/src/components/lists_new/lists_new.js b/src/components/lists_new/lists_new.js new file mode 100644 index 00000000..7e3470fa --- /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: 'list-timeline', params: { id: list.id } }) + }) + } + } +} + +export default ListsNew -- cgit v1.2.3-70-g09d2 From 891fbf996d7ddd415d99ea9065d54b0f493b5422 Mon Sep 17 00:00:00 2001 From: Alexander Tumin Date: Sat, 6 Aug 2022 21:39:08 +0300 Subject: Lists implementation: make route naming consistent --- src/boot/routes.js | 4 ++-- src/components/lists_card/lists_card.vue | 4 ++-- src/components/lists_edit/lists_edit.js | 2 +- src/components/lists_menu/lists_menu_content.vue | 2 +- src/components/lists_new/lists_new.js | 2 +- src/components/lists_timeline/lists_timeline.js | 2 +- src/components/timeline_menu/timeline_menu.js | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/components/lists_new/lists_new.js') diff --git a/src/boot/routes.js b/src/boot/routes.js index 8bb7d196..95e47199 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -77,8 +77,8 @@ export default (store) => { { name: 'about', path: '/about', component: About }, { name: 'user-profile', path: '/:_(users)?/:name', component: UserProfile }, { name: 'lists', path: '/lists', component: Lists }, - { name: 'list-timeline', path: '/lists/:id', component: ListsTimeline }, - { name: 'list-edit', path: '/lists/:id/edit', component: ListsEdit } + { name: 'lists-timeline', path: '/lists/:id', component: ListsTimeline }, + { name: 'lists-edit', path: '/lists/:id/edit', component: ListsEdit } ] if (store.state.instance.pleromaChatMessagesAvailable) { diff --git a/src/components/lists_card/lists_card.vue b/src/components/lists_card/lists_card.vue index c0d58f18..13866d8c 100644 --- a/src/components/lists_card/lists_card.vue +++ b/src/components/lists_card/lists_card.vue @@ -1,13 +1,13 @@