Skip to content

Commit 7d77866

Browse files
committed
fix the bug that crashes codeSnippet when you remove a child component when used in the htmlQueue
1 parent 25aa946 commit 7d77866

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

src/store/actions.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,6 @@ const actions = {
344344

345345
// end of Drag-and-drop /////////////////////////////////
346346

347-
// Place Child Components among the Html Elements //////////////
348-
[types.upgradeIconGridWithChildComponent]: ({ commit }, payload) => {
349-
commit(types.UPGRADE_ICON_GRID_WITH_CHILD_COMPONENT, payload)
350-
},
351-
352-
// end of Place Child Components among the Html Elements ////////
353-
354347
// Loading ///////////////////////////////////////////////////////
355348
[types.openProject]: ({ commit }, payload) => {
356349
commit(types.REMOVE_ALL_STATE_PROPS_ACTIONS)

src/store/mutations.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const mutations = {
330330
}
331331
}
332332
}
333-
//
333+
//update the component name in the htmlList of all components if it is a child component
334334
for (const item of Object.values(state.componentMap)) {
335335
if (item.htmlList) {
336336
const newArray = [...item.htmlList];
@@ -357,26 +357,6 @@ const mutations = {
357357
item.htmlList = newArray
358358
}
359359
}
360-
/*
361-
const breadthFirstSearchParent = (array, id) => {
362-
const queue = [...array.filter(el => typeof el === 'object')]
363-
while (queue.length) {
364-
const evaluated = queue.shift()
365-
for (let i = 0; i < evaluated.children.length; i++) {
366-
if (evaluated.children[i].id === id) {
367-
return {
368-
evaluated,
369-
index: i
370-
}
371-
}
372-
if (evaluated.children.length) {
373-
queue.push(...evaluated.children)
374-
}
375-
}
376-
}
377-
}
378-
*/
379-
380360

381361
},
382362

@@ -804,6 +784,28 @@ const mutations = {
804784
// const newMap = { ...state.componentMap };
805785
// state.componentMap = { ...newMap };
806786

787+
//delete the instances of the Child Component in the activeComponent's htmlList
788+
const componentName = state.activeComponent;
789+
const htmlList = state.componentMap[componentName].htmlList.slice(0);
790+
791+
// splice out child componenets even if nested
792+
function deleteChildFromHtmlList(array, payload) {
793+
for(let i = array.length; i--;) {
794+
795+
if(array[i].children.length) {
796+
deleteChildFromHtmlList(array[i].children, payload)
797+
}
798+
if(array[i].text === payload) {
799+
array.splice(i, 1)
800+
}
801+
802+
}
803+
}
804+
deleteChildFromHtmlList(htmlList, payload);
805+
806+
//updates the htmlList with the child components deleted
807+
state.componentMap[componentName].htmlList = htmlList;
808+
807809
//delete the parent because the payload is no longer a child to the acitive component
808810
delete state.componentMap[payload].parent[state.activeComponent];
809811

@@ -819,14 +821,6 @@ const mutations = {
819821
state.componentMap[state.activeComponent];
820822
}
821823
},
822-
// update Parent's icon Grid with Child Component
823-
[types.UPGRADE_ICON_GRID_WITH_CHILD_COMPONENT]: (state, payload) => {
824-
//Update available Child Components options to be place along side the HTML Elements every time the Child Components are updated
825-
//mutation function with the same payload and using the activeComponent
826-
//if the payload is not and html option added, if it is then delete it
827-
828-
},
829-
830824
// invoked when element is double clicked, changing the boolean value
831825
[types.UPDATE_OPEN_MODAL]: (state, payload) => {
832826
state.modalOpen = payload;

src/store/types.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ export const SET_SELECTED_ID_DRAG = 'SET_SELECTED_ID_DRAG'
8484
export const SET_SELECTED_ID_DROP = 'SET_SELECTED_ID_DROP'
8585
export const DRAG_DROP_SORT_HTML_ELEMENTS = 'DRAG_DROP_SORT_HTML_ELEMENTS'
8686
export const DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS = 'DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS'
87-
//
88-
export const UPGRADE_ICON_GRID_WITH_CHILD_COMPONENT = 'UPGRADE_ICON_GRID_WITH_CHILD_COMPONENT'
87+
8988

9089
// Actions
9190
export const openNoteModal = 'openNoteModal'
@@ -167,9 +166,6 @@ export const setSelectedIdDrag = 'setSelectedIdDrag'
167166
export const setSelectedIdDrop = 'setSelectedIdDrop'
168167
export const dragDropSortHtmlElements = 'dragDropSortHtmlElements'
169168
export const dragDropSortSelectedHtmlElements = 'dragDropSortSelectedHtmlElements'
170-
//
171-
export const upgradeIconGridWithChildComponent = 'upgradeIconGridWithChildComponent'
172-
173169

174170

175171
// inactive mutations

0 commit comments

Comments
 (0)