Skip to content

Commit 2e43188

Browse files
authored
Merge pull request #31 from deanfchung/master
delete button now sets active component to empty string. it also works
2 parents ceaf265 + 7cb2767 commit 2e43188

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

src/components/CodeSnippet.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default {
4444
// calls createTemplate and createBoiler to generate snippet
4545
createCodeSnippet (componentName, children) {
4646
let result = `${this.createTemplate(componentName, children)}${this.createBoiler(componentName, children)}`
47-
console.log(`createCodeSnippet result: ${result}`)
47+
//console.log(`createCodeSnippet result: ${result}`)
4848
return result
4949
},
5050
createTemplate (componentName, children) {
@@ -58,7 +58,7 @@ export default {
5858
return `<template>\n ${output}${templateTagStr} </div>\n</template>`
5959
},
6060
writeTemplateTag (componentName) {
61-
console.log('writeTemplateTag invoked!')
61+
//console.log('writeTemplateTag invoked!')
6262
// create reference object
6363
const htmlElementMap = {
6464
div: ['<div>', '</div>'],
@@ -82,7 +82,7 @@ export default {
8282
outputStr += htmlElementMap[el.text][1]
8383
outputStr += ` \n`
8484
}
85-
console.log(`outputStr from writeTemplateTag: ${outputStr}`)
85+
//console.log(`outputStr from writeTemplateTag: ${outputStr}`)
8686
return outputStr
8787
},
8888
createBoiler (componentName, children) {
@@ -110,7 +110,7 @@ export default {
110110
},
111111
// updates code snippet, but broken cause children undefined, shows `function () { [native code] }`
112112
updated () {
113-
console.log(`code: ${this.createCodeSnippet(this.activeComponent, this.componentMap[this.activeComponent].children)}`)
113+
//console.log(`code: ${this.createCodeSnippet(this.activeComponent, this.componentMap[this.activeComponent].children)}`)
114114
this.code = `${this.createCodeSnippet(this.activeComponent, this.componentMap[this.activeComponent].children)}`
115115
},
116116
beforeDestroy () {

src/components/CreateComponent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</div>
1919
<ParentMultiselect />
2020
<br />
21-
<q-btn id="add-component-btn" class="primary" color="secondary" label="Create Component" icon-right="add" @click="handleClick" :disabled="!componentNameInputValue" />
21+
<q-btn id="add-component-btn" class="glossy" color="teal" label="Create Component" icon-right="add" @click="handleClick" :disabled="!componentNameInputValue" />
2222
</div>
2323
</template>
2424

src/components/HomeSideDropDownItems/ComponentList.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{componentData.componentName}}
1616
<!-- <br> -->
1717
</div>
18-
<q-btn round flat icon="highlight_off" />
18+
<q-btn round flat icon="highlight_off" v-on:click.stop='handleClick(componentData)'/>
1919
</div>
2020
</q-item-section>
2121
</q-item>
@@ -44,11 +44,14 @@ export default {
4444
}
4545
},
4646
methods: {
47-
...mapActions(['setActiveComponent']),
47+
...mapActions(['setActiveComponent','deleteComponent']),
4848
onActivated (componentData) {
4949
this.setActiveComponent(componentData.componentName)
5050
this.activeComponentData.isActive = true
51-
console.log('this.activeComponent', this.activeComponent)
51+
},
52+
handleClick (componentData) {
53+
this.deleteComponent(componentData)
54+
this.setActiveComponent('')
5255
}
5356
}
5457
}

src/components/Tree.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default {
6565
this.tree = build['App']
6666
}
6767
},
68-
mounted () {
68+
created () {
6969
this.buildTree()
7070
}
7171
}

src/store/actions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ const actions = {
117117
commit(types.PARENT_SELECTED, payload)
118118
},
119119
[types.deleteRoute]: ({ state, commit }, payload) => {
120-
console.log('stat in actions:', state)
121120
commit(types.DELETE_ROUTE, payload)
121+
},
122+
[types.deleteComponent]: ({state, commit }, payload) => {
123+
console.log('payload in actions:', payload)
124+
commit(types.DELETE_COMPONENT, payload)
122125
}
123126
}
124127

src/store/mutations.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ const mutations = {
133133
state.routes = Object.assign({}, payload)
134134
},
135135
// invoked when a component is deleted
136-
//
137136
[types.SET_ACTIVE_ROUTE_ARRAY]: (state, payload) => {
138137
state.routes[state.activeRoute] = payload
139138
},
@@ -187,7 +186,19 @@ const mutations = {
187186
delete stateCopy.routes[payload]
188187
delete stateCopy.componentMap[payload]
189188
state = stateCopy
190-
console.log('aftermutations state', state)
189+
},
190+
[types.DELETE_COMPONENT]: (state,payload) => {
191+
const stateCopy = state
192+
let compArr = stateCopy.routes[stateCopy.activeRoute]
193+
for (let i = 0; i < compArr.length;i++){
194+
if (compArr[i].componentName==payload.componentName){
195+
compArr.splice(i,1)
196+
}
197+
}
198+
delete state.componentMap[payload.componentName]
199+
state.routes[state.activeRoute] = compArr
200+
console.log('new state', state)
201+
191202
}
192203
}
193204

src/store/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
4040
export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
4141
export const PARENT_SELECTED = 'PARENT_SELECTED'
4242
export const DELETE_ROUTE = 'DELETE_ROUTE'
43+
export const DELETE_COMPONENT = 'DELETE_COMPONENT'
4344

4445
// Actions
4546
export const registerComponent = 'registerComponent'
@@ -73,3 +74,4 @@ export const updateComponentNameInputValue = 'updateComponentNameInputValue'
7374
export const updateOpenModal = 'updateOpenModal'
7475
export const parentSelected = 'parentSelected'
7576
export const deleteRoute = 'deleteRoute'
77+
export const deleteComponent = 'deleteComponent'

0 commit comments

Comments
 (0)