Browse Source

add pages store module

axolotle 2 years ago
parent
commit
2f784cbe29
2 changed files with 36 additions and 1 deletions
  1. 3 1
      src/store/index.js
  2. 33 0
      src/store/modules/pages.js

+ 3 - 1
src/store/index.js

@@ -4,6 +4,7 @@ import Vuex from 'vuex'
 import nodes from './nodes'
 import library from './modules/library'
 import kit from './modules/kit'
+import pages from './modules/pages'
 
 Vue.use(Vuex)
 
@@ -11,6 +12,7 @@ export default new Vuex.Store({
   ...nodes,
   modules: {
     library,
-    kit
+    kit,
+    pages
   }
 })

+ 33 - 0
src/store/modules/pages.js

@@ -0,0 +1,33 @@
+import api from '@/api'
+import { Page } from '@/api/queries'
+
+
+export default {
+  state: {
+    welcome: undefined,
+    intro: undefined,
+    ids: {
+      welcome: 1,
+      intro: 207
+    }
+  },
+
+  mutations: {
+    'SET_PAGE' (state, { slug, page }) {
+      state[slug] = page
+    }
+  },
+
+  actions: {
+    async 'QUERY_PAGE' ({ state, commit, dispatch, getters }, slug) {
+      if (state[slug] !== undefined) return state[slug]
+      return api.query(Page, { id: state.ids[slug] }).then(data => {
+        commit('SET_PAGE', { slug, page: data.page })
+        return state[slug]
+      })
+    }
+  },
+
+  getters: {
+  }
+}