add texts store & add Textsdepart query

This commit is contained in:
axolotle
2021-03-01 13:26:27 +01:00
parent b8465290ce
commit 038d91b5b5
5 changed files with 58 additions and 69 deletions
-24
View File
@@ -1,24 +0,0 @@
export default {
namespaced: true,
// initial state
state: {
// items: [],
},
// getters
getters: {
},
// mutations
mutations: {
},
// actions
actions: {
},
// methods
methods: {
}
}
+47
View File
@@ -0,0 +1,47 @@
import api from '@/api'
import { print } from 'graphql/language/printer'
import {
TextsDepart, TextRef, TextdepartRecursive
} from '@/api/queries'
export default {
state: {
textsDepart: undefined
},
mutations: {
'SET_TEXTS_DEPART' (state, texts) {
state.textsDepart = texts
}
},
actions: {
'GET_TEXTS_DEPART' ({ state, commit }) {
return api.post('', { query: print(TextsDepart) }).then(({ data }) => {
commit('SET_TEXTS_DEPART', data.data.textsdepart)
return state.textsDepart
})
},
'GET_TEXT' ({ state }, { id }) {
return api.post('', { query: print(TextRef), variables: { id } })
.then(data => (data.data.data))
},
'GET_TREE' ({ dispatch }, id) {
return api.post('', { query: print(TextdepartRecursive), variables: { id } })
.then(({ data }) => (data.data.textref))
}
},
getters: {
textsDepartOptions: state => {
if (!state.textsDepart) return undefined
return state.textsDepart.map(({ id, title }) => ({
value: id,
text: `(${id}) ${title}`
}))
}
}
}