From 0a00c9beb2a7e183563d4e71dab6e5d336735c3f Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 24 Oct 2021 13:25:22 +0100 Subject: [PATCH] :nut_and_bolt: Adds updateSection functionality to store --- src/store.js | 11 +++++++++++ src/utils/StoreMutations.js | 1 + 2 files changed, 12 insertions(+) diff --git a/src/store.js b/src/store.js index c99d9da9..c9cc1414 100644 --- a/src/store.js +++ b/src/store.js @@ -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 */ diff --git a/src/utils/StoreMutations.js b/src/utils/StoreMutations.js index 9cb70861..ba3cb51f 100644 --- a/src/utils/StoreMutations.js +++ b/src/utils/StoreMutations.js @@ -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