From 966927da4ce20c6b071adc67845695e2ef090471 Mon Sep 17 00:00:00 2001 From: axolotle Date: Thu, 8 Jul 2021 17:54:15 +0200 Subject: [PATCH] add gallery store --- src/store/index.js | 2 ++ src/store/modules/gallery.js | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/store/modules/gallery.js diff --git a/src/store/index.js b/src/store/index.js index 09f18a8..e4042df 100644 --- a/src/store/index.js +++ b/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 gallery from './modules/gallery' import pages from './modules/pages' Vue.use(Vuex) @@ -13,6 +14,7 @@ export default new Vuex.Store({ modules: { library, kit, + gallery, pages } }) diff --git a/src/store/modules/gallery.js b/src/store/modules/gallery.js new file mode 100644 index 0000000..d1de870 --- /dev/null +++ b/src/store/modules/gallery.js @@ -0,0 +1,40 @@ +export default { + state: { + creation: undefined + }, + + mutations: { + 'SET_CREATION' (state, id) { + state.creation = id + } + }, + + actions: { + async 'INIT_GALLERY' ({ state, commit, dispatch, getters }) { + const ids = await dispatch('GET_ALL_NODES_IDS', { variant: 'creation', dataLevel: 'full' }) + dispatch('OPEN_CREATION', ids[ids.length - 1]) + return dispatch('GET_NODES', { ids, dataLevel: 'full' }) + }, + + async 'OPEN_CREATION' ({ state, commit, dispatch }, id) { + commit('SET_CREATION', id) + commit('ADD_HISTORY_ENTRIES', [id]) + return dispatch('GET_NODE', { id, dataLevel: 'full' }) + } + }, + + getters: { + creations: (state, getters, rootState) => { + const ids = rootState.ids.creation + if (ids === undefined) return + const nodes = ids.map(id => rootState.nodes[id]) + if (nodes.some(node => node === undefined)) return + return nodes + }, + + creation: (state, getters, rootState) => { + if (state.creation === undefined || state.creation === null) return state.creation + return rootState.nodes[state.creation] + } + } +}