From 98bcb7f7038cd5c43f27f1e0324a5a6cb5bf7f41 Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 14 Jun 2021 12:23:17 +0200 Subject: [PATCH] reorganise library store --- src/store/modules/library.js | 58 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/store/modules/library.js b/src/store/modules/library.js index 13a6411..9516a5b 100644 --- a/src/store/modules/library.js +++ b/src/store/modules/library.js @@ -15,12 +15,15 @@ import { export default { state: { - tags: undefined, - strangeness: [0, 1, 2, 3, 4], - nodeDepartId: undefined, trees: {}, - mode: undefined, nodebook: undefined, + + // LibraryOptions options + strangeness: [0, 1, 2, 3, 4], + tagsOptions: [], + // LibraryOptions state + mode: undefined, + nodeDepartId: undefined, search: '' }, @@ -58,8 +61,8 @@ export default { // │ │├─╯ │ │ │ ││││╰─╮ // ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯ - 'SET_TAGS' (state, tags) { - state.tags = tags + 'SET_TAGS_OPTIONS' (state, tags) { + state.tagsOptions = tags.map(tag => ({ value: tag.id, text: tag.name })) }, 'SET_MODE' (state, mode) { @@ -144,7 +147,7 @@ export default { 'GET_ALL_TAGS' ({ state, commit }) { if (state.tags !== undefined) return state.tags return api.query(AllTags).then(data => { - commit('SET_TAGS', data.tags) + commit('SET_TAGS_OPTIONS', data.tags) return state.tags }) }, @@ -170,29 +173,13 @@ export default { }, getters: { + // LibraryOptions state mode: state => state.mode, nodeDepartId: state => state.nodeDepartId, search: state => state.search, - nodebook: (state, getters, rootState) => { - if (!state.nodebook) return [] - return state.nodebook.map(([parentId, ...childrenIds]) => { - return { - parent: rootState.nodes[parentId], - children: childrenIds.map(id => rootState.nodes[id]) - } - }) - }, - - activeNodes: state => { - if (!state.nodebook) return [] - return state.nodebook.reduce((acc, ids) => [...acc, ...ids], []) - }, - - tagsOptions: state => { - if (state.tags === undefined) return [] - return state.tags.map(tag => ({ value: tag.id, text: tag.name })) - }, + // LibraryOptions options + tagsOptions: state => state.tagsOptions, nodesDepartsOptions: (state, getters, rootState) => { const departIds = rootState.ids.depart @@ -207,6 +194,18 @@ export default { }) }, + // Library + nodebook: (state, getters, rootState) => { + if (!state.nodebook) return [] + return state.nodebook.map(([parentId, ...childrenIds]) => { + return { + parent: rootState.nodes[parentId], + children: childrenIds.map(id => rootState.nodes[id]) + } + }) + }, + + // LibraryList orderedTextsDepart: (state, getters, rootState) => { const departIds = rootState.ids.depart if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return @@ -224,8 +223,15 @@ export default { }, {}) }, + // LibraryTree nodeTree: (state, rootState) => { return state.trees[state.nodeDepartId] || { nodes: [], links: [] } + }, + + // Commons + activeNodes: state => { + if (!state.nodebook) return [] + return state.nodebook.reduce((acc, ids) => [...acc, ...ids], []) } } }