Skip to content

Commit bd38fa0

Browse files
committed
delete from nested works
1 parent 7b6462a commit bd38fa0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/components/HomeQueue.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- <div class="list-group-item" @dblclick="setActiveElement(element)" v-for="(element) in renderList" :key="element[1] + Date.now()"> -->
1515
<div :class="activeHTML === element[2] ? 'list-group-item-selected' : 'list-group-item'" @dblclick="setActiveElement(element)" v-for="(element) in renderList" :key="element[1] + Date.now()">
1616
{{ element[0] }}
17-
<i class="fas fa fa-trash fa-md" @click="deleteElement(element[1])"></i>
17+
<i class="fas fa fa-trash fa-md" @click="deleteElement(element[2])"></i>
1818
</div>
1919
</draggable>
2020
</section>
@@ -80,9 +80,9 @@ export default {
8080
},
8181
methods: {
8282
...mapActions(['setActiveHTML', 'setActiveLayer']),
83-
deleteElement (index) {
83+
deleteElement (id) {
8484
if (this.activeComponent === '') this.$store.dispatch(deleteSelectedElement, index)
85-
else this.$store.dispatch(deleteFromComponentHtmlList, index)
85+
else this.$store.dispatch(deleteFromComponentHtmlList, id)
8686
},
8787
setActiveElement (element) {
8888
this.$store.dispatch(setActiveHTML, element)

src/store/mutations.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const breadthFirstSearchParent = (array,id) => {
3232
let evaluated = queue.shift()
3333
for(let i=0; i<evaluated.children.length;i++){
3434
if(evaluated.children[i].id === id){
35-
return evaluated
35+
return {
36+
evaluated:evaluated,
37+
index : i
3638
}
3739
}
3840
if (evaluated.children.length){
@@ -41,7 +43,7 @@ const breadthFirstSearchParent = (array,id) => {
4143
}
4244
console.log("We shouldn't be ever getting here, how did you even search an id that didn't exist?")
4345
}
44-
46+
}
4547
const mutations = {
4648

4749
[types.SET_ACTIVE_LAYER]: (state, payload) =>{
@@ -78,7 +80,7 @@ const mutations = {
7880
let newID = breadthFirstSearchParent(state.componentMap[state.activeComponent].htmlList, payload)
7981
//console.log("new ID here", newID)
8082
let newLayer = {...state.activeLayer}
81-
newLayer.id = newID.id
83+
newLayer.id = newID.evaluated.id
8284
newLayer.lineage.pop()
8385
console.log("We should have gone up a level ", newLayer)
8486
state.activeLayer = newLayer
@@ -215,11 +217,15 @@ const mutations = {
215217
})
216218
},
217219

218-
[types.DELETE_FROM_COMPONENT_HTML_LIST]: (state, idx) => {
220+
[types.DELETE_FROM_COMPONENT_HTML_LIST]: (state, id) => {
219221
const componentName = state.activeComponent
220222
const htmlList = state.componentMap[componentName].htmlList.slice(0)
221223
// splice out selected element and return resulting array
222-
htmlList.splice(idx, 1)
224+
let element = breadthFirstSearchParent(htmlList, id);
225+
console.log("This is element", element)
226+
element.evaluated.children.splice(element.index,1);
227+
// htmlList.splice(idx, 1)
228+
223229
state.componentMap[componentName].htmlList = htmlList
224230
},
225231
[types.SET_CLICKED_ELEMENT_LIST]: (state, payload) => {

0 commit comments

Comments
 (0)