소스 검색

reorganise library store

axolotle 3 년 전
부모
커밋
98bcb7f703
1개의 변경된 파일32개의 추가작업 그리고 26개의 파일을 삭제
  1. 32 26
      src/store/modules/library.js

+ 32 - 26
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], [])
     }
   }
 }