From 5f6aadcb957163bf63a8f6447fa0661848a54f3a Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 8 Apr 2024 20:34:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Adds=20mutations=20for=20setting=20?= =?UTF-8?q?sub-config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store.js | 20 +++++++++----------- src/utils/StoreMutations.js | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/store.js b/src/store.js index 632aa64a..5bbde59a 100644 --- a/src/store.js +++ b/src/store.js @@ -18,7 +18,7 @@ const { INITIALIZE_ROOT_CONFIG, SET_CONFIG, SET_ROOT_CONFIG, - SET_CONFIG_ID, + SET_CURRENT_CONFIG_INFO, SET_MODAL_OPEN, SET_LANGUAGE, SET_ITEM_LAYOUT, @@ -46,10 +46,9 @@ const store = new Vuex.Store({ state: { config: {}, // The current config being used, and rendered to the UI rootConfig: null, // Always the content of main config file, never used directly - currentConfigId: null, // When on sub-page, this will be page ID / name. null = root config editMode: false, // While true, the user can drag and edit items + sections modalOpen: false, // KB shortcut functionality will be disabled when modal is open - currentConfigInfo: undefined, // For multi-page support, will store info about config file + currentConfigInfo: {}, // For multi-page support, will store info about config file navigateConfToTab: undefined, // Used to switch active tab in config modal }, getters: { @@ -71,8 +70,8 @@ const store = new Vuex.Store({ return state.config.pages || []; }, theme(state) { - const localStorageKey = state.currentConfigId - ? `${localStorageKeys.THEME}-${state.currentConfigId}` : localStorageKeys.THEME; + const localStorageKey = state.currentConfigInfo.confId + ? `${localStorageKeys.THEME}-${state.currentConfigInfo.confId}` : localStorageKeys.THEME; const localTheme = localStorage[localStorageKey]; // Return either theme from local storage, or from appConfig return localTheme || state.config.appConfig.theme || defaultTheme; @@ -153,9 +152,8 @@ const store = new Vuex.Store({ if (!config.appConfig) config.appConfig = {}; state.config = config; }, - /* When using multi-page, this is the ID of currently displayed config */ - [SET_CONFIG_ID](state, subConfigId) { - state.currentConfigId = subConfigId; + [SET_CURRENT_CONFIG_INFO](state, subConfigInfo) { + state.currentConfigInfo = subConfigInfo; }, [SET_LANGUAGE](state, lang) { const newConfig = state.config; @@ -282,7 +280,7 @@ const store = new Vuex.Store({ const newConfig = { ...state.config }; newConfig.appConfig.theme = theme; state.config = newConfig; - const pageId = state.currentConfigId; + const pageId = state.currentConfigInfo.confId; const themeStoreKey = pageId ? `${localStorageKeys.THEME}-${pageId}` : localStorageKeys.THEME; localStorage.setItem(themeStoreKey, theme); @@ -341,7 +339,7 @@ const store = new Vuex.Store({ const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG); if (!subConfigId) { // Use root config as config commit(SET_CONFIG, rootConfig); - commit(SET_CONFIG_ID, null); + commit(SET_CURRENT_CONFIG_INFO, {}); return rootConfig; } else { // Find and format path to fetch sub-config from @@ -362,7 +360,7 @@ const store = new Vuex.Store({ configContent.pages = rootConfig.pages; configContent.appConfig.theme = theme; commit(SET_CONFIG, configContent); - commit(SET_CONFIG_ID, subConfigId); + commit(SET_CURRENT_CONFIG_INFO, { confPath: subConfigPath, confId: subConfigId }); return configContent; }).catch((err) => { ErrorHandler(`Unable to load config from '${subConfigPath}'`, err); diff --git a/src/utils/StoreMutations.js b/src/utils/StoreMutations.js index 6ca0001b..2d06a36d 100644 --- a/src/utils/StoreMutations.js +++ b/src/utils/StoreMutations.js @@ -5,7 +5,7 @@ const KEY_NAMES = [ 'INITIALIZE_MULTI_PAGE_CONFIG', 'SET_CONFIG', 'SET_ROOT_CONFIG', - 'SET_CONFIG_ID', + 'SET_CURRENT_CONFIG_INFO', 'SET_CURRENT_SUB_PAGE', 'SET_MODAL_OPEN', 'SET_LANGUAGE',