From e3b1afc3256cd903a3e0c77d05f43d4d964af14f Mon Sep 17 00:00:00 2001 From: axolotle Date: Thu, 10 Jun 2021 19:21:39 +0200 Subject: [PATCH] rename main store module --- src/store/index.js | 4 +- src/store/modules/texts.js | 94 -------------------------------- src/store/{texts.js => nodes.js} | 0 3 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 src/store/modules/texts.js rename src/store/{texts.js => nodes.js} (100%) diff --git a/src/store/index.js b/src/store/index.js index 9c188c7..95933e4 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,13 +1,13 @@ import Vue from 'vue' import Vuex from 'vuex' -import texts from './texts' +import nodes from './nodes' import library from './modules/library' Vue.use(Vuex) export default new Vuex.Store({ - ...texts, + ...nodes, modules: { library } diff --git a/src/store/modules/texts.js b/src/store/modules/texts.js deleted file mode 100644 index 393e3bd..0000000 --- a/src/store/modules/texts.js +++ /dev/null @@ -1,94 +0,0 @@ -import api from '@/api' -import { formatData } from '@/helpers/formatter' -import { print } from 'graphql/language/printer' -import { - TextsDepart, TextCard, TextdepartRecursive -} from '@/api/queries' -import TextdepartRecursiveWithDepth from '@/api/queries/TextdepartRecursiveWithDepth.gql' - -export default { - state: { - textsDepart: undefined, - textDepart: undefined - }, - - mutations: { - 'SET_TEXTS_DEPART' (state, texts) { - state.textsDepart = texts - }, - - 'SET_TEXT_DEPART' (state, text) { - state.textDepart = text - } - }, - - actions: { - 'GET_TEXTS_DEPART' ({ state, commit }) { - return api.post('', { query: print(TextsDepart) }).then(({ data }) => { - commit('SET_TEXTS_DEPART', formatData(data.data.textsdepart)) - return state.textsDepart - }) - }, - - 'GET_TEXT' (store, { id }) { - return api.post('', { query: print(TextCard), variables: { id } }) - .then(data => formatData(data.data.data.text, true)) - }, - - 'GET_TREE' (store, id) { - return api.post('', { query: print(TextdepartRecursive), variables: { id } }) - .then(({ data }) => formatData(data.data.textref)) - }, - - 'GET_TREE_WITH_DEPTH' ({ state, commit }, { id, depth = 4 }) { - const baseQuery = print(TextdepartRecursiveWithDepth) - function formatQuery (str, depth) { - if (depth > 0) { - return formatQuery( - str.replace('INPUT', '...TextrefTreeFields\nsiblings: text_en_rebond {\nINPUT\n}'), - --depth - ) - } else { - return str.replace('INPUT', '...TextrefTreeFields') - } - } - commit('SET_TEXT_DEPART', undefined) - return api.post('', { query: formatQuery(baseQuery, depth), variables: { id } }).then(({ data }) => { - console.log(data.data) - commit('SET_TEXT_DEPART', formatData(data.data.textref)) - return state.textDepart - }) - } - }, - - getters: { - textsDepart: state => state.textsDepart, - - textDepart: state => state.textDepart, - - textsDepartOptions: state => { - if (!state.textsDepart) return undefined - return state.textsDepart.map(({ id, title }) => ({ - value: id, - text: `(${id}) ${title}` - })) - }, - - orderedParents: state => { - // FIXME duplicates references if multiple authors ? - if (!state.textsDepart) return undefined - return state.textsDepart.sort((a, b) => { - if (!b.authors) return -1 - if (!a.authors) return +1 - if (a.authors[0].last_name < b.authors[0].last_name) return -1 - if (a.authors[0].last_name > b.authors[0].last_name) return 1 - return 0 - }).reduce((dict, text) => { - const firstChar = text.authors ? text.authors[0].last_name[0] : 'Pas de noms' - if (!(firstChar in dict)) dict[firstChar] = [] - dict[firstChar].push(text) - return dict - }, {}) - } - } -} diff --git a/src/store/texts.js b/src/store/nodes.js similarity index 100% rename from src/store/texts.js rename to src/store/nodes.js