🔩 Adds updateSection functionality to store

This commit is contained in:
Alicia Sykes 2021-10-24 13:25:22 +01:00
parent 87bf9263db
commit 0a00c9beb2
2 changed files with 12 additions and 0 deletions

View File

@ -17,6 +17,7 @@ const {
SET_EDIT_MODE,
UPDATE_PAGE_INFO,
UPDATE_APP_CONFIG,
UPDATE_SECTION,
} = Keys;
const store = new Vuex.Store({
@ -44,6 +45,10 @@ const store = new Vuex.Store({
visibleComponents(state, getters) {
return componentVisibility(getters.appConfig);
},
// eslint-disable-next-line arrow-body-style
getSectionByIndex: (state, getters) => (index) => {
return getters.sections[index];
},
getItemById: (state, getters) => (id) => {
let item;
getters.sections.forEach(sec => {
@ -90,6 +95,12 @@ const store = new Vuex.Store({
newConfig.appConfig = newAppConfig;
state.config = newConfig;
},
[UPDATE_SECTION](state, payload) {
const { sectionIndex, sectionData } = payload;
const newConfig = { ...state.config };
newConfig.sections[sectionIndex] = sectionData;
state.config = newConfig;
},
},
actions: {
/* Called when app first loaded. Reads config and sets state */

View File

@ -8,6 +8,7 @@ const KEY_NAMES = [
'UPDATE_ITEM',
'UPDATE_PAGE_INFO',
'UPDATE_APP_CONFIG',
'UPDATE_SECTION',
];
// Convert array of key names into an object, and export