🏪 Updates status logs in the store

This commit is contained in:
Alicia Sykes 2021-11-07 21:04:54 +00:00
parent fd04241700
commit 9bd3ef0a46

View File

@ -31,17 +31,15 @@ const {
REMOVE_ITEM, REMOVE_ITEM,
INSERT_ITEM, INSERT_ITEM,
UPDATE_CUSTOM_CSS, UPDATE_CUSTOM_CSS,
CONF_MENU_INDEX,
} = Keys; } = Keys;
const editorLog = (logMessage) => {
InfoHandler(logMessage, InfoKeys.EDITOR);
};
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
config: {}, config: {},
editMode: false, // While true, the user can drag and edit items + sections editMode: false, // While true, the user can drag and edit items + sections
modalOpen: false, // KB shortcut functionality will be disabled when modal is open modalOpen: false, // KB shortcut functionality will be disabled when modal is open
navigateConfToTab: undefined, // Used to switch active tab in config modal
}, },
getters: { getters: {
config(state) { config(state) {
@ -107,7 +105,7 @@ const store = new Vuex.Store({
}, },
[SET_EDIT_MODE](state, editMode) { [SET_EDIT_MODE](state, editMode) {
if (editMode !== state.editMode) { if (editMode !== state.editMode) {
editorLog(editMode ? 'Edit session started' : 'Edit session ended'); InfoHandler(editMode ? 'Edit session started' : 'Edit session ended', InfoKeys.EDITOR);
state.editMode = editMode; state.editMode = editMode;
} }
}, },
@ -118,7 +116,7 @@ const store = new Vuex.Store({
section.items.forEach((item, itemIndex) => { section.items.forEach((item, itemIndex) => {
if (item.id === itemId) { if (item.id === itemId) {
newConfig.sections[secIndex].items[itemIndex] = newItem; newConfig.sections[secIndex].items[itemIndex] = newItem;
editorLog('Item updated'); InfoHandler('Item updated', InfoKeys.EDITOR);
} }
}); });
}); });
@ -128,40 +126,40 @@ const store = new Vuex.Store({
const newConfig = state.config; const newConfig = state.config;
newConfig.pageInfo = newPageInfo; newConfig.pageInfo = newPageInfo;
state.config = newConfig; state.config = newConfig;
editorLog('Page info updated'); InfoHandler('Page info updated', InfoKeys.EDITOR);
}, },
[SET_APP_CONFIG](state, newAppConfig) { [SET_APP_CONFIG](state, newAppConfig) {
const newConfig = state.config; const newConfig = state.config;
newConfig.appConfig = newAppConfig; newConfig.appConfig = newAppConfig;
state.config = newConfig; state.config = newConfig;
editorLog('App config updated'); InfoHandler('App config updated', InfoKeys.EDITOR);
}, },
[SET_SECTIONS](state, newSections) { [SET_SECTIONS](state, newSections) {
const newConfig = state.config; const newConfig = state.config;
newConfig.sections = newSections; newConfig.sections = newSections;
state.config = newConfig; state.config = newConfig;
editorLog('Sections updated'); InfoHandler('Sections updated', InfoKeys.EDITOR);
}, },
[UPDATE_SECTION](state, payload) { [UPDATE_SECTION](state, payload) {
const { sectionIndex, sectionData } = payload; const { sectionIndex, sectionData } = payload;
const newConfig = { ...state.config }; const newConfig = { ...state.config };
newConfig.sections[sectionIndex] = sectionData; newConfig.sections[sectionIndex] = sectionData;
state.config = newConfig; state.config = newConfig;
editorLog('Section updated'); InfoHandler('Section updated', InfoKeys.EDITOR);
}, },
[INSERT_SECTION](state, newSection) { [INSERT_SECTION](state, newSection) {
const newConfig = { ...state.config }; const newConfig = { ...state.config };
newSection.items = []; newSection.items = [];
newConfig.sections.push(newSection); newConfig.sections.push(newSection);
state.config = newConfig; state.config = newConfig;
editorLog('New section added'); InfoHandler('New section added', InfoKeys.EDITOR);
}, },
[REMOVE_SECTION](state, payload) { [REMOVE_SECTION](state, payload) {
const { sectionIndex, sectionName } = payload; const { sectionIndex, sectionName } = payload;
const newConfig = { ...state.config }; const newConfig = { ...state.config };
if (newConfig.sections[sectionIndex].name === sectionName) { if (newConfig.sections[sectionIndex].name === sectionName) {
newConfig.sections.splice(sectionIndex, 1); newConfig.sections.splice(sectionIndex, 1);
editorLog('Section removed'); InfoHandler('Section removed', InfoKeys.EDITOR);
} }
state.config = newConfig; state.config = newConfig;
}, },
@ -171,7 +169,7 @@ const store = new Vuex.Store({
config.sections.forEach((section) => { config.sections.forEach((section) => {
if (section.name === targetSection) { if (section.name === targetSection) {
section.items.push(newItem); section.items.push(newItem);
editorLog('New item added'); InfoHandler('New item added', InfoKeys.EDITOR);
} }
}); });
config.sections = applyItemId(config.sections); config.sections = applyItemId(config.sections);
@ -188,7 +186,7 @@ const store = new Vuex.Store({
} else { } else {
section.items.push(newItem); section.items.push(newItem);
} }
editorLog('Item copied'); InfoHandler('Item copied', InfoKeys.EDITOR);
} }
}); });
config.sections = applyItemId(config.sections); config.sections = applyItemId(config.sections);
@ -202,7 +200,7 @@ const store = new Vuex.Store({
section.items.forEach((item, index) => { section.items.forEach((item, index) => {
if (item.id === itemId) { if (item.id === itemId) {
section.items.splice(index, 1); section.items.splice(index, 1);
editorLog('Item removed'); InfoHandler('Item removed', InfoKeys.EDITOR);
} }
}); });
} }
@ -233,6 +231,9 @@ const store = new Vuex.Store({
state.config.appConfig.customCss = customCss; state.config.appConfig.customCss = customCss;
InfoHandler('Custom colors updated', InfoKeys.VISUAL); InfoHandler('Custom colors updated', InfoKeys.VISUAL);
}, },
[CONF_MENU_INDEX](state, index) {
state.navigateConfToTab = index;
},
}, },
actions: { actions: {
/* Called when app first loaded. Reads config and sets state */ /* Called when app first loaded. Reads config and sets state */