✨ Implements move, copy and delete item, and delete section functionality
This commit is contained in:
41
src/store.js
41
src/store.js
@@ -19,7 +19,9 @@ const {
|
||||
UPDATE_PAGE_INFO,
|
||||
UPDATE_APP_CONFIG,
|
||||
UPDATE_SECTION,
|
||||
REMOVE_SECTION,
|
||||
COPY_ITEM,
|
||||
REMOVE_ITEM,
|
||||
} = Keys;
|
||||
|
||||
const store = new Vuex.Store({
|
||||
@@ -59,6 +61,15 @@ const store = new Vuex.Store({
|
||||
});
|
||||
return item;
|
||||
},
|
||||
getParentSectionOfItem: (state, getters) => (itemId) => {
|
||||
let foundSection;
|
||||
getters.sections.forEach((section) => {
|
||||
section.items.forEach((item) => {
|
||||
if (item.id === itemId) foundSection = section;
|
||||
});
|
||||
});
|
||||
return foundSection;
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
[UPDATE_CONFIG](state, config) {
|
||||
@@ -103,18 +114,44 @@ const store = new Vuex.Store({
|
||||
newConfig.sections[sectionIndex] = sectionData;
|
||||
state.config = newConfig;
|
||||
},
|
||||
[REMOVE_SECTION](state, payload) {
|
||||
const { sectionIndex, sectionName } = payload;
|
||||
const newConfig = { ...state.config };
|
||||
if (newConfig.sections[sectionIndex].name === sectionName) {
|
||||
newConfig.sections.splice(sectionIndex, 1);
|
||||
}
|
||||
state.config = newConfig;
|
||||
},
|
||||
[COPY_ITEM](state, payload) {
|
||||
const { item, toSection } = payload;
|
||||
const { item, toSection, appendTo } = payload;
|
||||
const config = { ...state.config };
|
||||
const newItem = { ...item };
|
||||
config.sections.forEach((section) => {
|
||||
if (section.name === toSection) {
|
||||
section.items.push(newItem);
|
||||
if (appendTo === 'Begining') {
|
||||
section.items.unshift(newItem);
|
||||
} else {
|
||||
section.items.push(newItem);
|
||||
}
|
||||
}
|
||||
});
|
||||
config.sections = applyItemId(config.sections);
|
||||
state.config = config;
|
||||
},
|
||||
[REMOVE_ITEM](state, payload) {
|
||||
const { itemId, sectionName } = payload;
|
||||
const config = { ...state.config };
|
||||
config.sections.forEach((section) => {
|
||||
if (section.name === sectionName) {
|
||||
section.items.forEach((item, index) => {
|
||||
if (item.id === itemId) {
|
||||
section.items.splice(index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
state.config = config;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/* Called when app first loaded. Reads config and sets state */
|
||||
|
||||
Reference in New Issue
Block a user