Migrates lists module to store
This commit is contained in:
parent
ad7d47f440
commit
8eff081468
13 changed files with 248 additions and 109 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { useListsStore } from '../../stores/lists'
|
||||
import ListsCard from '../lists_card/lists_card.vue'
|
||||
|
||||
const Lists = {
|
||||
|
|
@ -11,7 +12,7 @@ const Lists = {
|
|||
},
|
||||
computed: {
|
||||
lists () {
|
||||
return this.$store.state.lists.allLists
|
||||
return useListsStore().allLists
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { mapState, mapGetters } from 'vuex'
|
||||
import { mapState as mapPiniaState } from 'pinia'
|
||||
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
|
||||
import ListsUserSearch from '../lists_user_search/lists_user_search.vue'
|
||||
import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
|
||||
|
|
@ -10,6 +11,7 @@ import {
|
|||
faChevronLeft
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { useInterfaceStore } from '../../stores/interface'
|
||||
import { useListsStore } from '../../stores/lists'
|
||||
|
||||
library.add(
|
||||
faSearch,
|
||||
|
|
@ -38,12 +40,12 @@ const ListsNew = {
|
|||
},
|
||||
created () {
|
||||
if (!this.id) return
|
||||
this.$store.dispatch('fetchList', { listId: this.id })
|
||||
useListsStore().fetchList({ listId: this.id })
|
||||
.then(() => {
|
||||
this.title = this.findListTitle(this.id)
|
||||
this.titleDraft = this.title
|
||||
})
|
||||
this.$store.dispatch('fetchListAccounts', { listId: this.id })
|
||||
useListsStore().fetchListAccounts({ listId: this.id })
|
||||
.then(() => {
|
||||
this.membersUserIds = this.findListAccounts(this.id)
|
||||
this.membersUserIds.forEach(userId => {
|
||||
|
|
@ -65,7 +67,8 @@ const ListsNew = {
|
|||
...mapState({
|
||||
currentUser: state => state.users.currentUser
|
||||
}),
|
||||
...mapGetters(['findUser', 'findListTitle', 'findListAccounts'])
|
||||
...mapPiniaState(useListsStore, ['findListTitle', 'findListAccounts']),
|
||||
...mapGetters(['findUser'])
|
||||
},
|
||||
methods: {
|
||||
onInput () {
|
||||
|
|
@ -96,10 +99,10 @@ const ListsNew = {
|
|||
return this.addedUserIds.has(user.id)
|
||||
},
|
||||
addUser (user) {
|
||||
this.$store.dispatch('addListAccount', { accountId: user.id, listId: this.id })
|
||||
useListsStore().addListAccount({ accountId: user.id, listId: this.id })
|
||||
},
|
||||
removeUser (userId) {
|
||||
this.$store.dispatch('removeListAccount', { accountId: userId, listId: this.id })
|
||||
useListsStore().removeListAccount({ accountId: userId, listId: this.id })
|
||||
},
|
||||
onSearchLoading (results) {
|
||||
this.searchLoading = true
|
||||
|
|
@ -112,17 +115,16 @@ const ListsNew = {
|
|||
this.searchUserIds = results
|
||||
},
|
||||
updateListTitle () {
|
||||
this.$store.dispatch('setList', { listId: this.id, title: this.titleDraft })
|
||||
useListsStore().setList({ listId: this.id, title: this.titleDraft })
|
||||
.then(() => {
|
||||
this.title = this.findListTitle(this.id)
|
||||
})
|
||||
},
|
||||
createList () {
|
||||
this.$store.dispatch('createList', { title: this.titleDraft })
|
||||
useListsStore().createList({ title: this.titleDraft })
|
||||
.then((list) => {
|
||||
return this
|
||||
.$store
|
||||
.dispatch('setListAccounts', { listId: list.id, accountIds: [...this.addedUserIds] })
|
||||
return useListsStore()
|
||||
.setListAccounts({ listId: list.id, accountIds: [...this.addedUserIds] })
|
||||
.then(() => list.id)
|
||||
})
|
||||
.then((listId) => {
|
||||
|
|
@ -137,7 +139,7 @@ const ListsNew = {
|
|||
})
|
||||
},
|
||||
deleteList () {
|
||||
this.$store.dispatch('deleteList', { listId: this.id })
|
||||
useListsStore().deleteList({ listId: this.id })
|
||||
this.$router.push({ name: 'lists' })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { mapState } from 'vuex'
|
||||
import { mapState as mapPiniaState } from 'pinia'
|
||||
import NavigationEntry from 'src/components/navigation/navigation_entry.vue'
|
||||
import { getListEntries } from 'src/components/navigation/filter.js'
|
||||
import { useListsStore } from '../../stores/lists'
|
||||
|
||||
export const ListsMenuContent = {
|
||||
props: [
|
||||
|
|
@ -10,8 +12,10 @@ export const ListsMenuContent = {
|
|||
NavigationEntry
|
||||
},
|
||||
computed: {
|
||||
...mapPiniaState(useListsStore, {
|
||||
lists: getListEntries
|
||||
}),
|
||||
...mapState({
|
||||
lists: getListEntries,
|
||||
currentUser: state => state.users.currentUser,
|
||||
privateMode: state => state.instance.private,
|
||||
federating: state => state.instance.federating
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { useListsStore } from '../../stores/lists'
|
||||
import Timeline from '../timeline/timeline.vue'
|
||||
const ListsTimeline = {
|
||||
data () {
|
||||
|
|
@ -17,14 +18,14 @@ const ListsTimeline = {
|
|||
this.listId = route.params.id
|
||||
this.$store.dispatch('stopFetchingTimeline', 'list')
|
||||
this.$store.commit('clearTimeline', { timeline: 'list' })
|
||||
this.$store.dispatch('fetchList', { listId: this.listId })
|
||||
useListsStore().fetchList({ listId: this.listId })
|
||||
this.$store.dispatch('startFetchingTimeline', { timeline: 'list', listId: this.listId })
|
||||
}
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.listId = this.$route.params.id
|
||||
this.$store.dispatch('fetchList', { listId: this.listId })
|
||||
useListsStore().fetchList({ listId: this.listId })
|
||||
this.$store.dispatch('startFetchingTimeline', { timeline: 'list', listId: this.listId })
|
||||
},
|
||||
unmounted () {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export const filterNavigation = (list = [], { hasChats, hasAnnouncements, isFede
|
|||
})
|
||||
}
|
||||
|
||||
export const getListEntries = state => state.lists.allLists.map(list => ({
|
||||
export const getListEntries = store => store.allLists.map(list => ({
|
||||
name: 'list-' + list.id,
|
||||
routeObject: { name: 'lists-timeline', params: { id: list.id } },
|
||||
labelRaw: list.title,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { mapState } from 'vuex'
|
||||
import { mapState as mapPiniaState } from 'pinia'
|
||||
import { TIMELINES, ROOT_ITEMS, routeTo } from 'src/components/navigation/navigation.js'
|
||||
import { getListEntries, filterNavigation } from 'src/components/navigation/filter.js'
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ import {
|
|||
faStream,
|
||||
faList
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { useListsStore } from '../../stores/lists'
|
||||
|
||||
library.add(
|
||||
faUsers,
|
||||
|
|
@ -38,8 +40,10 @@ const NavPanel = {
|
|||
getters () {
|
||||
return this.$store.getters
|
||||
},
|
||||
...mapPiniaState(useListsStore, {
|
||||
lists: getListEntries
|
||||
}),
|
||||
...mapState({
|
||||
lists: getListEntries,
|
||||
currentUser: state => state.users.currentUser,
|
||||
followRequestCount: state => state.api.followRequests.length,
|
||||
privateMode: state => state.instance.private,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
faChevronDown
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { useInterfaceStore } from '../../stores/interface'
|
||||
import { useListsStore } from '../../stores/lists'
|
||||
|
||||
library.add(faChevronDown)
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ const TimelineMenu = {
|
|||
return '#' + this.$route.params.tag
|
||||
}
|
||||
if (route === 'lists-timeline') {
|
||||
return this.$store.getters.findListTitle(this.$route.params.id)
|
||||
return useListsStore().findListTitle(this.$route.params.id)
|
||||
}
|
||||
const i18nkey = timelineNames()[this.$route.name]
|
||||
return i18nkey ? this.$t(i18nkey) : route
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||
import { faChevronRight } from '@fortawesome/free-solid-svg-icons'
|
||||
import { mapState } from 'vuex'
|
||||
import { mapState } from 'pinia'
|
||||
|
||||
import DialogModal from '../dialog_modal/dialog_modal.vue'
|
||||
import Popover from '../popover/popover.vue'
|
||||
import { useListsStore } from '../../stores/lists'
|
||||
|
||||
library.add(faChevronRight)
|
||||
|
||||
|
|
@ -22,8 +23,8 @@ const UserListMenu = {
|
|||
this.$store.dispatch('fetchUserInLists', this.user.id)
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
allLists: state => state.lists.allLists
|
||||
...mapState(useListsStore, {
|
||||
allLists: store => store.allLists
|
||||
}),
|
||||
inListsSet () {
|
||||
return new Set(this.user.inLists.map(x => x.id))
|
||||
|
|
@ -39,12 +40,12 @@ const UserListMenu = {
|
|||
methods: {
|
||||
toggleList (listId) {
|
||||
if (this.inListsSet.has(listId)) {
|
||||
this.$store.dispatch('removeListAccount', { accountId: this.user.id, listId }).then((response) => {
|
||||
useListsStore().removeListAccount({ accountId: this.user.id, listId }).then((response) => {
|
||||
if (!response.ok) { return }
|
||||
this.$store.dispatch('fetchUserInLists', this.user.id)
|
||||
})
|
||||
} else {
|
||||
this.$store.dispatch('addListAccount', { accountId: this.user.id, listId }).then((response) => {
|
||||
useListsStore().addListAccount({ accountId: this.user.id, listId }).then((response) => {
|
||||
if (!response.ok) { return }
|
||||
this.$store.dispatch('fetchUserInLists', this.user.id)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue