Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85832853
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/stores/lists.js b/src/stores/lists.js
index 3d4dedbf2b..7669386aed 100644
--- a/src/stores/lists.js
+++ b/src/stores/lists.js
@@ -1,116 +1,110 @@
import { defineStore } from 'pinia'
import { remove, find } from 'lodash'
-export const defaultState = {
- allLists: [],
- allListsObject: {}
-}
-
-export const getters = {
- findListTitle (state) {
- return (id) => {
- if (!this.allListsObject[id]) return
- return this.allListsObject[id].title
- }
- },
- findListAccounts (state) {
- return (id) => [...this.allListsObject[id].accountIds]
- }
-}
-
-export const actions = {
- setLists (value) {
- this.allLists = value
- },
- createList ({ title }) {
- return window.vuex.state.api.backendInteractor.createList({ title })
- .then((list) => {
- this.setList({ listId: list.id, title })
- return list
- })
- },
- fetchList ({ listId }) {
- return window.vuex.state.api.backendInteractor.getList({ listId })
- .then((list) => this.setList({ listId: list.id, title: list.title }))
- },
- fetchListAccounts ({ listId }) {
- return window.vuex.state.api.backendInteractor.getListAccounts({ listId })
- .then((accountIds) => {
- if (!this.allListsObject[listId]) {
- this.allListsObject[listId] = { accountIds: [] }
- }
- this.allListsObject[listId].accountIds = accountIds
- })
- },
- setList ({ listId, title }) {
- if (!this.allListsObject[listId]) {
- this.allListsObject[listId] = { accountIds: [] }
- }
- this.allListsObject[listId].title = title
-
- const entry = find(this.allLists, { id: listId })
- if (!entry) {
- this.allLists.push({ id: listId, title })
- } else {
- entry.title = title
+export const useListsStore = defineStore('lists', {
+ state: () => ({
+ allLists: [],
+ allListsObject: {}
+ }),
+ getters: {
+ findListTitle (state) {
+ return (id) => {
+ if (!this.allListsObject[id]) return
+ return this.allListsObject[id].title
+ }
+ },
+ findListAccounts (state) {
+ return (id) => [...this.allListsObject[id].accountIds]
}
},
- setListAccounts ({ listId, accountIds }) {
- const saved = this.allListsObject[listId].accountIds || []
- const added = accountIds.filter(id => !saved.includes(id))
- const removed = saved.filter(id => !accountIds.includes(id))
- if (!this.allListsObject[listId]) {
- this.allListsObject[listId] = { accountIds: [] }
- }
- this.allListsObject[listId].accountIds = accountIds
- if (added.length > 0) {
- window.vuex.state.api.backendInteractor.addAccountsToList({ listId, accountIds: added })
- }
- if (removed.length > 0) {
- window.vuex.state.api.backendInteractor.removeAccountsFromList({ listId, accountIds: removed })
+ actions: {
+ setLists (value) {
+ this.allLists = value
+ },
+ createList ({ title }) {
+ return window.vuex.state.api.backendInteractor.createList({ title })
+ .then((list) => {
+ this.setList({ listId: list.id, title })
+ return list
+ })
+ },
+ fetchList ({ listId }) {
+ return window.vuex.state.api.backendInteractor.getList({ listId })
+ .then((list) => this.setList({ listId: list.id, title: list.title }))
+ },
+ fetchListAccounts ({ listId }) {
+ return window.vuex.state.api.backendInteractor.getListAccounts({ listId })
+ .then((accountIds) => {
+ if (!this.allListsObject[listId]) {
+ this.allListsObject[listId] = { accountIds: [] }
+ }
+ this.allListsObject[listId].accountIds = accountIds
+ })
+ },
+ setList ({ listId, title }) {
+ if (!this.allListsObject[listId]) {
+ this.allListsObject[listId] = { accountIds: [] }
+ }
+ this.allListsObject[listId].title = title
+
+ const entry = find(this.allLists, { id: listId })
+ if (!entry) {
+ this.allLists.push({ id: listId, title })
+ } else {
+ entry.title = title
+ }
+ },
+ setListAccounts ({ listId, accountIds }) {
+ const saved = this.allListsObject[listId].accountIds || []
+ const added = accountIds.filter(id => !saved.includes(id))
+ const removed = saved.filter(id => !accountIds.includes(id))
+ if (!this.allListsObject[listId]) {
+ this.allListsObject[listId] = { accountIds: [] }
+ }
+ this.allListsObject[listId].accountIds = accountIds
+ if (added.length > 0) {
+ window.vuex.state.api.backendInteractor.addAccountsToList({ listId, accountIds: added })
+ }
+ if (removed.length > 0) {
+ window.vuex.state.api.backendInteractor.removeAccountsFromList({ listId, accountIds: removed })
+ }
+ },
+ addListAccount ({ listId, accountId }) {
+ return window.vuex.state
+ .api
+ .backendInteractor
+ .addAccountsToList({ listId, accountIds: [accountId] })
+ .then((result) => {
+ if (!this.allListsObject[listId]) {
+ this.allListsObject[listId] = { accountIds: [] }
+ }
+ this.allListsObject[listId].accountIds.push(accountId)
+ return result
+ })
+ },
+ removeListAccount ({ listId, accountId }) {
+ return window.vuex.state
+ .api
+ .backendInteractor
+ .removeAccountsFromList({ listId, accountIds: [accountId] })
+ .then((result) => {
+ if (!this.allListsObject[listId]) {
+ this.allListsObject[listId] = { accountIds: [] }
+ }
+ const { accountIds } = this.allListsObject[listId]
+ const set = new Set(accountIds)
+ set.delete(accountId)
+ this.allListsObject[listId].accountIds = [...set]
+
+ return result
+ })
+ },
+ deleteList ({ listId }) {
+ window.vuex.state.api.backendInteractor.deleteList({ listId })
+
+ delete this.allListsObject[listId]
+ remove(this.allLists, list => list.id === listId)
}
- },
- addListAccount ({ listId, accountId }) {
- return window.vuex.state
- .api
- .backendInteractor
- .addAccountsToList({ listId, accountIds: [accountId] })
- .then((result) => {
- if (!this.allListsObject[listId]) {
- this.allListsObject[listId] = { accountIds: [] }
- }
- this.allListsObject[listId].accountIds.push(accountId)
- return result
- })
- },
- removeListAccount ({ listId, accountId }) {
- return window.vuex.state
- .api
- .backendInteractor
- .removeAccountsFromList({ listId, accountIds: [accountId] })
- .then((result) => {
- if (!this.allListsObject[listId]) {
- this.allListsObject[listId] = { accountIds: [] }
- }
- const { accountIds } = this.allListsObject[listId]
- const set = new Set(accountIds)
- set.delete(accountId)
- this.allListsObject[listId].accountIds = [...set]
-
- return result
- })
- },
- deleteList ({ listId }) {
- window.vuex.state.api.backendInteractor.deleteList({ listId })
-
- delete this.allListsObject[listId]
- remove(this.allLists, list => list.id === listId)
}
-}
-
-export const useListsStore = defineStore('lists', {
- state: () => (defaultState),
- getters,
- actions
})
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 2, 9:18 AM (2 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1804149
Default Alt Text
(7 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline