logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/
commit: d5b554f5afc1423d31e0f39ce90e0074b471423f
parent 391f7e0711f7060dfdb3d788a68c3353fdd24769
Author: Henry Jameson <me@hjkos.com>
Date:   Mon,  3 Feb 2025 16:37:53 +0200

fix tests

Diffstat:

Msrc/main.js2--
Dsrc/modules/lists.js130-------------------------------------------------------------------------------
Msrc/stores/lists.js2+-
3 files changed, 1 insertion(+), 133 deletions(-)

diff --git a/src/main.js b/src/main.js @@ -7,7 +7,6 @@ import './lib/event_target_polyfill.js' import instanceModule from './modules/instance.js' import statusesModule from './modules/statuses.js' import notificationsModule from './modules/notifications.js' -import listsModule from './modules/lists.js' import usersModule from './modules/users.js' import apiModule from './modules/api.js' import configModule from './modules/config.js' @@ -94,7 +93,6 @@ const persistedStateOptions = { instance: instanceModule, // TODO refactor users/statuses modules, they depend on each other users: usersModule, - lists: listsModule, statuses: statusesModule, notifications: notificationsModule, api: apiModule, diff --git a/src/modules/lists.js b/src/modules/lists.js @@ -1,130 +0,0 @@ -import { remove, find } from 'lodash' - -export const defaultState = { - allLists: [], - allListsObject: {} -} - -export const mutations = { - setLists (state, value) { - state.allLists = value - }, - setList (state, { listId, title }) { - if (!state.allListsObject[listId]) { - state.allListsObject[listId] = { accountIds: [] } - } - state.allListsObject[listId].title = title - - const entry = find(state.allLists, { id: listId }) - if (!entry) { - state.allLists.push({ id: listId, title }) - } else { - entry.title = title - } - }, - setListAccounts (state, { listId, accountIds }) { - if (!state.allListsObject[listId]) { - state.allListsObject[listId] = { accountIds: [] } - } - state.allListsObject[listId].accountIds = accountIds - }, - addListAccount (state, { listId, accountId }) { - if (!state.allListsObject[listId]) { - state.allListsObject[listId] = { accountIds: [] } - } - state.allListsObject[listId].accountIds.push(accountId) - }, - removeListAccount (state, { listId, accountId }) { - if (!state.allListsObject[listId]) { - state.allListsObject[listId] = { accountIds: [] } - } - const { accountIds } = state.allListsObject[listId] - const set = new Set(accountIds) - set.delete(accountId) - state.allListsObject[listId].accountIds = [...set] - }, - deleteList (state, { listId }) { - delete state.allListsObject[listId] - remove(state.allLists, list => list.id === listId) - } -} - -const actions = { - setLists ({ commit }, value) { - commit('setLists', value) - }, - createList ({ rootState, commit }, { title }) { - return rootState.api.backendInteractor.createList({ title }) - .then((list) => { - commit('setList', { listId: list.id, title }) - return list - }) - }, - fetchList ({ rootState, commit }, { listId }) { - return rootState.api.backendInteractor.getList({ listId }) - .then((list) => commit('setList', { listId: list.id, title: list.title })) - }, - fetchListAccounts ({ rootState, commit }, { listId }) { - return rootState.api.backendInteractor.getListAccounts({ listId }) - .then((accountIds) => commit('setListAccounts', { listId, accountIds })) - }, - setList ({ rootState, commit }, { listId, title }) { - rootState.api.backendInteractor.updateList({ listId, title }) - commit('setList', { listId, title }) - }, - setListAccounts ({ rootState, commit }, { listId, accountIds }) { - const saved = rootState.lists.allListsObject[listId].accountIds || [] - const added = accountIds.filter(id => !saved.includes(id)) - const removed = saved.filter(id => !accountIds.includes(id)) - commit('setListAccounts', { listId, accountIds }) - if (added.length > 0) { - rootState.api.backendInteractor.addAccountsToList({ listId, accountIds: added }) - } - if (removed.length > 0) { - rootState.api.backendInteractor.removeAccountsFromList({ listId, accountIds: removed }) - } - }, - addListAccount ({ rootState, commit }, { listId, accountId }) { - return rootState - .api - .backendInteractor - .addAccountsToList({ listId, accountIds: [accountId] }) - .then((result) => { - commit('addListAccount', { listId, accountId }) - return result - }) - }, - removeListAccount ({ rootState, commit }, { listId, accountId }) { - return rootState - .api - .backendInteractor - .removeAccountsFromList({ listId, accountIds: [accountId] }) - .then((result) => { - commit('removeListAccount', { listId, accountId }) - return result - }) - }, - deleteList ({ rootState, commit }, { listId }) { - rootState.api.backendInteractor.deleteList({ listId }) - commit('deleteList', { listId }) - } -} - -export const getters = { - findListTitle: state => id => { - if (!state.allListsObject[id]) return - return state.allListsObject[id].title - }, - findListAccounts: state => id => { - return [...state.allListsObject[id].accountIds] - } -} - -const lists = { - state: defaultState, - mutations, - actions, - getters -} - -export default lists diff --git a/src/stores/lists.js b/src/stores/lists.js @@ -56,7 +56,7 @@ export const useListsStore = defineStore('lists', { } }, setListAccounts ({ listId, accountIds }) { - const saved = this.allListsObject[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]) {