mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-23 13:45:33 +02:00
🏪 Adds setup / update section to store
This commit is contained in:
parent
beb532b967
commit
a237ec0827
45
src/store.js
45
src/store.js
@ -12,20 +12,24 @@ Vue.use(Vuex);
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
INITIALIZE_CONFIG,
|
INITIALIZE_CONFIG,
|
||||||
UPDATE_CONFIG,
|
SET_CONFIG,
|
||||||
SET_MODAL_OPEN,
|
SET_MODAL_OPEN,
|
||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
SET_ITEM_LAYOUT,
|
SET_ITEM_LAYOUT,
|
||||||
SET_ITEM_SIZE,
|
SET_ITEM_SIZE,
|
||||||
|
SET_THEME,
|
||||||
UPDATE_ITEM,
|
UPDATE_ITEM,
|
||||||
SET_EDIT_MODE,
|
SET_EDIT_MODE,
|
||||||
UPDATE_PAGE_INFO,
|
SET_PAGE_INFO,
|
||||||
UPDATE_APP_CONFIG,
|
SET_APP_CONFIG,
|
||||||
|
SET_SECTIONS,
|
||||||
UPDATE_SECTION,
|
UPDATE_SECTION,
|
||||||
|
INSERT_SECTION,
|
||||||
REMOVE_SECTION,
|
REMOVE_SECTION,
|
||||||
COPY_ITEM,
|
COPY_ITEM,
|
||||||
REMOVE_ITEM,
|
REMOVE_ITEM,
|
||||||
INSERT_ITEM,
|
INSERT_ITEM,
|
||||||
|
UPDATE_CUSTOM_CSS,
|
||||||
} = Keys;
|
} = Keys;
|
||||||
|
|
||||||
const editorLog = (logMessage) => {
|
const editorLog = (logMessage) => {
|
||||||
@ -48,6 +52,9 @@ const store = new Vuex.Store({
|
|||||||
appConfig(state) {
|
appConfig(state) {
|
||||||
return state.config.appConfig || {};
|
return state.config.appConfig || {};
|
||||||
},
|
},
|
||||||
|
theme(state) {
|
||||||
|
return state.config.appConfig.theme;
|
||||||
|
},
|
||||||
sections(state) {
|
sections(state) {
|
||||||
return filterUserSections(state.config.sections || []);
|
return filterUserSections(state.config.sections || []);
|
||||||
},
|
},
|
||||||
@ -80,7 +87,7 @@ const store = new Vuex.Store({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
[UPDATE_CONFIG](state, config) {
|
[SET_CONFIG](state, config) {
|
||||||
state.config = config;
|
state.config = config;
|
||||||
},
|
},
|
||||||
[SET_LANGUAGE](state, lang) {
|
[SET_LANGUAGE](state, lang) {
|
||||||
@ -110,18 +117,24 @@ const store = new Vuex.Store({
|
|||||||
});
|
});
|
||||||
state.config = newConfig;
|
state.config = newConfig;
|
||||||
},
|
},
|
||||||
[UPDATE_PAGE_INFO](state, newPageInfo) {
|
[SET_PAGE_INFO](state, newPageInfo) {
|
||||||
const newConfig = state.config;
|
const newConfig = state.config;
|
||||||
newConfig.pageInfo = newPageInfo;
|
newConfig.pageInfo = newPageInfo;
|
||||||
state.config = newConfig;
|
state.config = newConfig;
|
||||||
editorLog('Page info updated');
|
editorLog('Page info updated');
|
||||||
},
|
},
|
||||||
[UPDATE_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');
|
editorLog('App config updated');
|
||||||
},
|
},
|
||||||
|
[SET_SECTIONS](state, newSections) {
|
||||||
|
const newConfig = state.config;
|
||||||
|
newConfig.sections = newSections;
|
||||||
|
state.config = newConfig;
|
||||||
|
editorLog('Sections updated');
|
||||||
|
},
|
||||||
[UPDATE_SECTION](state, payload) {
|
[UPDATE_SECTION](state, payload) {
|
||||||
const { sectionIndex, sectionData } = payload;
|
const { sectionIndex, sectionData } = payload;
|
||||||
const newConfig = { ...state.config };
|
const newConfig = { ...state.config };
|
||||||
@ -129,6 +142,13 @@ const store = new Vuex.Store({
|
|||||||
state.config = newConfig;
|
state.config = newConfig;
|
||||||
editorLog('Section updated');
|
editorLog('Section updated');
|
||||||
},
|
},
|
||||||
|
[INSERT_SECTION](state, newSection) {
|
||||||
|
const newConfig = { ...state.config };
|
||||||
|
newSection.items = [];
|
||||||
|
newConfig.sections.push(newSection);
|
||||||
|
state.config = newConfig;
|
||||||
|
editorLog('New section added');
|
||||||
|
},
|
||||||
[REMOVE_SECTION](state, payload) {
|
[REMOVE_SECTION](state, payload) {
|
||||||
const { sectionIndex, sectionName } = payload;
|
const { sectionIndex, sectionName } = payload;
|
||||||
const newConfig = { ...state.config };
|
const newConfig = { ...state.config };
|
||||||
@ -156,7 +176,7 @@ const store = new Vuex.Store({
|
|||||||
const newItem = { ...item };
|
const newItem = { ...item };
|
||||||
config.sections.forEach((section) => {
|
config.sections.forEach((section) => {
|
||||||
if (section.name === toSection) {
|
if (section.name === toSection) {
|
||||||
if (appendTo === 'Begining') {
|
if (appendTo === 'beginning') {
|
||||||
section.items.unshift(newItem);
|
section.items.unshift(newItem);
|
||||||
} else {
|
} else {
|
||||||
section.items.push(newItem);
|
section.items.push(newItem);
|
||||||
@ -182,19 +202,28 @@ const store = new Vuex.Store({
|
|||||||
});
|
});
|
||||||
state.config = config;
|
state.config = config;
|
||||||
},
|
},
|
||||||
|
[SET_THEME](state, theme) {
|
||||||
|
const newConfig = { ...state.config };
|
||||||
|
newConfig.appConfig.theme = theme;
|
||||||
|
state.config = newConfig;
|
||||||
|
InfoHandler('Theme updated', InfoKeys.VISUAL);
|
||||||
|
},
|
||||||
[SET_ITEM_LAYOUT](state, layout) {
|
[SET_ITEM_LAYOUT](state, layout) {
|
||||||
state.config.appConfig.layout = layout;
|
state.config.appConfig.layout = layout;
|
||||||
},
|
},
|
||||||
[SET_ITEM_SIZE](state, iconSize) {
|
[SET_ITEM_SIZE](state, iconSize) {
|
||||||
state.config.appConfig.iconSize = iconSize;
|
state.config.appConfig.iconSize = iconSize;
|
||||||
},
|
},
|
||||||
|
[UPDATE_CUSTOM_CSS](state, customCss) {
|
||||||
|
state.config.appConfig.customCss = customCss;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
/* Called when app first loaded. Reads config and sets state */
|
/* Called when app first loaded. Reads config and sets state */
|
||||||
[INITIALIZE_CONFIG]({ commit }) {
|
[INITIALIZE_CONFIG]({ commit }) {
|
||||||
const deepCopy = (json) => JSON.parse(JSON.stringify(json));
|
const deepCopy = (json) => JSON.parse(JSON.stringify(json));
|
||||||
const config = deepCopy(new ConfigAccumulator().config());
|
const config = deepCopy(new ConfigAccumulator().config());
|
||||||
commit(UPDATE_CONFIG, config);
|
commit(SET_CONFIG, config);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
modules: {},
|
modules: {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user