mirror of
https://github.com/Lissy93/dashy.git
synced 2025-09-25 18:58:48 +02:00
✨ Adds mutations for setting sub-config
This commit is contained in:
parent
e2e581de59
commit
5f6aadcb95
20
src/store.js
20
src/store.js
@ -18,7 +18,7 @@ const {
|
|||||||
INITIALIZE_ROOT_CONFIG,
|
INITIALIZE_ROOT_CONFIG,
|
||||||
SET_CONFIG,
|
SET_CONFIG,
|
||||||
SET_ROOT_CONFIG,
|
SET_ROOT_CONFIG,
|
||||||
SET_CONFIG_ID,
|
SET_CURRENT_CONFIG_INFO,
|
||||||
SET_MODAL_OPEN,
|
SET_MODAL_OPEN,
|
||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
SET_ITEM_LAYOUT,
|
SET_ITEM_LAYOUT,
|
||||||
@ -46,10 +46,9 @@ const store = new Vuex.Store({
|
|||||||
state: {
|
state: {
|
||||||
config: {}, // The current config being used, and rendered to the UI
|
config: {}, // The current config being used, and rendered to the UI
|
||||||
rootConfig: null, // Always the content of main config file, never used directly
|
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
|
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
|
||||||
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
|
navigateConfToTab: undefined, // Used to switch active tab in config modal
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@ -71,8 +70,8 @@ const store = new Vuex.Store({
|
|||||||
return state.config.pages || [];
|
return state.config.pages || [];
|
||||||
},
|
},
|
||||||
theme(state) {
|
theme(state) {
|
||||||
const localStorageKey = state.currentConfigId
|
const localStorageKey = state.currentConfigInfo.confId
|
||||||
? `${localStorageKeys.THEME}-${state.currentConfigId}` : localStorageKeys.THEME;
|
? `${localStorageKeys.THEME}-${state.currentConfigInfo.confId}` : localStorageKeys.THEME;
|
||||||
const localTheme = localStorage[localStorageKey];
|
const localTheme = localStorage[localStorageKey];
|
||||||
// Return either theme from local storage, or from appConfig
|
// Return either theme from local storage, or from appConfig
|
||||||
return localTheme || state.config.appConfig.theme || defaultTheme;
|
return localTheme || state.config.appConfig.theme || defaultTheme;
|
||||||
@ -153,9 +152,8 @@ const store = new Vuex.Store({
|
|||||||
if (!config.appConfig) config.appConfig = {};
|
if (!config.appConfig) config.appConfig = {};
|
||||||
state.config = config;
|
state.config = config;
|
||||||
},
|
},
|
||||||
/* When using multi-page, this is the ID of currently displayed config */
|
[SET_CURRENT_CONFIG_INFO](state, subConfigInfo) {
|
||||||
[SET_CONFIG_ID](state, subConfigId) {
|
state.currentConfigInfo = subConfigInfo;
|
||||||
state.currentConfigId = subConfigId;
|
|
||||||
},
|
},
|
||||||
[SET_LANGUAGE](state, lang) {
|
[SET_LANGUAGE](state, lang) {
|
||||||
const newConfig = state.config;
|
const newConfig = state.config;
|
||||||
@ -282,7 +280,7 @@ const store = new Vuex.Store({
|
|||||||
const newConfig = { ...state.config };
|
const newConfig = { ...state.config };
|
||||||
newConfig.appConfig.theme = theme;
|
newConfig.appConfig.theme = theme;
|
||||||
state.config = newConfig;
|
state.config = newConfig;
|
||||||
const pageId = state.currentConfigId;
|
const pageId = state.currentConfigInfo.confId;
|
||||||
const themeStoreKey = pageId
|
const themeStoreKey = pageId
|
||||||
? `${localStorageKeys.THEME}-${pageId}` : localStorageKeys.THEME;
|
? `${localStorageKeys.THEME}-${pageId}` : localStorageKeys.THEME;
|
||||||
localStorage.setItem(themeStoreKey, 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);
|
const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
|
||||||
if (!subConfigId) { // Use root config as config
|
if (!subConfigId) { // Use root config as config
|
||||||
commit(SET_CONFIG, rootConfig);
|
commit(SET_CONFIG, rootConfig);
|
||||||
commit(SET_CONFIG_ID, null);
|
commit(SET_CURRENT_CONFIG_INFO, {});
|
||||||
return rootConfig;
|
return rootConfig;
|
||||||
} else {
|
} else {
|
||||||
// Find and format path to fetch sub-config from
|
// Find and format path to fetch sub-config from
|
||||||
@ -362,7 +360,7 @@ const store = new Vuex.Store({
|
|||||||
configContent.pages = rootConfig.pages;
|
configContent.pages = rootConfig.pages;
|
||||||
configContent.appConfig.theme = theme;
|
configContent.appConfig.theme = theme;
|
||||||
commit(SET_CONFIG, configContent);
|
commit(SET_CONFIG, configContent);
|
||||||
commit(SET_CONFIG_ID, subConfigId);
|
commit(SET_CURRENT_CONFIG_INFO, { confPath: subConfigPath, confId: subConfigId });
|
||||||
return configContent;
|
return configContent;
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
ErrorHandler(`Unable to load config from '${subConfigPath}'`, err);
|
ErrorHandler(`Unable to load config from '${subConfigPath}'`, err);
|
||||||
|
@ -5,7 +5,7 @@ const KEY_NAMES = [
|
|||||||
'INITIALIZE_MULTI_PAGE_CONFIG',
|
'INITIALIZE_MULTI_PAGE_CONFIG',
|
||||||
'SET_CONFIG',
|
'SET_CONFIG',
|
||||||
'SET_ROOT_CONFIG',
|
'SET_ROOT_CONFIG',
|
||||||
'SET_CONFIG_ID',
|
'SET_CURRENT_CONFIG_INFO',
|
||||||
'SET_CURRENT_SUB_PAGE',
|
'SET_CURRENT_SUB_PAGE',
|
||||||
'SET_MODAL_OPEN',
|
'SET_MODAL_OPEN',
|
||||||
'SET_LANGUAGE',
|
'SET_LANGUAGE',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user