🚧 You can now save items to VueX store, neat!

This commit is contained in:
Alicia Sykes
2021-10-16 21:03:26 +01:00
parent 677f0eea4e
commit f1fc013457
3 changed files with 37 additions and 7 deletions
+18 -1
View File
@@ -8,7 +8,12 @@ import filterUserSections from '@/utils/CheckSectionVisibility';
Vue.use(Vuex);
const { UPDATE_CONFIG, SET_MODAL_OPEN, SET_LANGUAGE } = Keys;
const {
UPDATE_CONFIG,
SET_MODAL_OPEN,
SET_LANGUAGE,
UPDATE_ITEM,
} = Keys;
const store = new Vuex.Store({
state: {
@@ -54,6 +59,18 @@ const store = new Vuex.Store({
[SET_MODAL_OPEN](state, modalOpen) {
state.modalOpen = modalOpen;
},
[UPDATE_ITEM](state, payload) {
const { itemId, newItem } = payload;
const newConfig = state.config;
newConfig.sections.forEach((section, secIndex) => {
section.items.forEach((item, itemIndex) => {
if (item.id === itemId) {
newConfig.sections[secIndex].items[itemIndex] = newItem;
}
});
});
state.config = newConfig;
},
},
actions: {
/* Called when app first loaded. Reads config and sets state */