Skip to content

Commit b55451a

Browse files
committed
fixed some lineage logic
1 parent 55d1def commit b55451a

File tree

7 files changed

+80
-20
lines changed

7 files changed

+80
-20
lines changed

src/App.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ let redoMixin = {
7070
}
7171
}
7272
});
73+
window.addEventListener('keydown', event => {
74+
if (event.ctrlKey && event.key === 'd') {
75+
event.preventDefault()
76+
if (this.$store.state.activeLayer.id !== '') {
77+
this.$store.dispatch('upOneLayer', this.$store.state.activeLayer.id)
78+
}
79+
}
80+
});
7381
7482
// console.log("do we want this? or this.$store.state?", this.$store.state)
7583
this.initialState = defaultState(this.$store.state)

src/components/CreateComponent.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@getClickedIcon="addToSelectedElementList"
1919
@activeElement="addToComponentElementList"
2020
@activeHTML="addNestedHTML"
21+
@activeLayer="addNestedNoActive"
2122
/>
2223
</div>
2324
<ParentMultiselect />
@@ -62,7 +63,8 @@ export default {
6263
'updateComponentNameInputValue',
6364
'setActiveComponent',
6465
'addToComponentElementList',
65-
'addNestedHTML'
66+
'addNestedHTML',
67+
'addNestedNoActive'
6668
]),
6769
handleClick () {
6870
if (!this.componentNameInputValue.trim()) {

src/components/HomeQueue.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default {
7979
}
8080
},
8181
methods: {
82-
...mapActions(['setActiveHTML']),
82+
...mapActions(['setActiveHTML', 'setActiveLayer']),
8383
deleteElement (index) {
8484
if (this.activeComponent === '') this.$store.dispatch(deleteSelectedElement, index)
8585
else this.$store.dispatch(deleteFromComponentHtmlList, index)

src/components/Icons.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ export default {
2626
},
2727
name: 'Icons',
2828
computed: {
29-
...mapState(['icons', 'activeComponent', 'componentMap', 'selectedElementList','activeHTML'])
29+
...mapState(['icons', 'activeComponent', 'componentMap', 'selectedElementList','activeHTML','activeLayer'])
3030
},
3131
methods: {
3232
changeState (elementName) {
3333
if (this.activeComponent === '') { this.$emit('getClickedIcon', {elementName, date:Date.now()}) }
3434
else {
35-
if(this.activeHTML === ''){
35+
if (this.activeHTML === '' && this.activeLayer.id ==='') {
3636
this.$emit('activeElement', {elementName,date:Date.now()})
3737
}
38-
else{
39-
this.$emit('activeHTML', {elementName, date:Date.now()})
38+
else if (this.activeLayer.id !== '' && this.activeHTML === '') {
39+
this.$emit('activeLayer', {elementName, date:Date.now()})
40+
}else {
41+
this.$emit('activeHTML', {elementName, date:Date.now()})
4042
}
4143
}
4244
}

src/store/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const actions = {
1313
commit(types.SET_ACTIVE_LAYER, payload)
1414
},
1515

16+
[types.upOneLayer]:({commit}, payload) => {
17+
commit(types.UP_ONE_LAYER, payload)
18+
},
19+
1620
[types.registerComponent]: ({ state, commit }, payload) => {
1721
const { componentName } = payload
1822
if (!state.componentMap[componentName]) {
@@ -118,6 +122,10 @@ const actions = {
118122
commit(types.ADD_NESTED_HTML, payload)
119123
},
120124

125+
[types.addNestedNoActive]:( {commit}, payload) =>{
126+
commit(types.ADD_NESTED_NO_ACTIVE,payload)
127+
},
128+
121129

122130
[types.setState]: ({ commit }, payload) => {
123131
commit(types.SET_STATE, payload)

src/store/mutations.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const breadthFirstSearchParent = (array,id) => {
3131
while(queue.length){
3232
let evaluated = queue.shift()
3333
for(let i=0; i<evaluated.children.length;i++){
34-
if(evaluated.children[i] === id){
34+
if(evaluated.children[i].id === id){
3535
return evaluated
3636
}
3737
}
@@ -47,24 +47,43 @@ const mutations = {
4747
[types.SET_ACTIVE_LAYER]: (state, payload) =>{
4848
let newLayer = cloneDeep(state.activeLayer)
4949

50-
//should only be reached if we change active component
51-
if (payload === '') {
50+
// //should only be reached if we change active component
51+
// if (payload === '') {
52+
// state.activeLayer = {
53+
// id:'',
54+
// lineage:[]
55+
// }
56+
// }
57+
// else{
58+
//htmlArray = state.componentMap[state.activeComponent].htmlList
59+
60+
newLayer.lineage.push(payload.text)
61+
62+
newLayer.id = payload.id
63+
// }
64+
state.activeLayer = newLayer
65+
state.activeHTML = ''
66+
},
67+
68+
[types.UP_ONE_LAYER]: (state, payload) => {
69+
//console.log("This is our payload",payload)
70+
// console.log("we are looking for the parent in here",state.componentMap[state.activeComponent].htmlList)
71+
if(state.activeLayer.lineage.length===1){
5272
state.activeLayer = {
53-
id:'',
54-
lineage:[]
73+
id: '',
74+
lineage: []
5575
}
5676
}
5777
else{
58-
//htmlArray = state.componentMap[state.activeComponent].htmlList
59-
if(newLayer.id === ''){
60-
newLayer.lineage.push(state.activeComponent)
61-
}
62-
else{
63-
newLayer.lineage.push(newLayer.id)
64-
}
65-
newLayer.id = payload
78+
let newID = breadthFirstSearchParent(state.componentMap[state.activeComponent].htmlList, payload)
79+
//console.log("new ID here", newID)
80+
let newLayer = {...state.activeLayer}
81+
newLayer.id = newID.id
82+
newLayer.lineage.pop()
83+
console.log("We should have gone up a level ", newLayer)
84+
state.activeLayer = newLayer
6685
}
67-
state.activeLayer = newLayer
86+
state.activeHTML = ''
6887
},
6988

7089

@@ -183,6 +202,19 @@ const mutations = {
183202
})
184203
},
185204

205+
// effectively the same as add nested, not happy with this, could do control flow earlier up somewhere?
206+
[types.ADD_NESTED_NO_ACTIVE]: (state,payload) => {
207+
const componentName = state.activeComponent
208+
const activeLayer = state.activeLayer
209+
state.componentMap[componentName] = { ...state.componentMap[componentName] }
210+
let nestedElement = breadthFirstSearch(state.componentMap[componentName].htmlList, activeLayer.id)
211+
nestedElement.children.push({
212+
text: payload.elementName,
213+
id: payload.date,
214+
children: []
215+
})
216+
},
217+
186218
[types.DELETE_FROM_COMPONENT_HTML_LIST]: (state, idx) => {
187219
const componentName = state.activeComponent
188220
const htmlList = state.componentMap[componentName].htmlList.slice(0)
@@ -282,6 +314,10 @@ const mutations = {
282314
[types.SET_ACTIVE_COMPONENT]: (state, payload) => {
283315
state.activeComponent = payload
284316
state.activeHTML = ''
317+
state.activeLayer = {
318+
id:'',
319+
lineage:[]
320+
}
285321
},
286322
[types.SET_ACTIVE_HTML_ELEMENT]: (state, payload) => {
287323
// console.log('text is ', payload[0])

src/store/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Mutations
2+
export const UP_ONE_LAYER = 'UP_ONE_LAYER'
3+
export const ADD_NESTED_NO_ACTIVE = 'ADD_NESTED_NO_ACTIVE'
24
export const SET_ACTIVE_LAYER = 'SET_ACTIVE_LAYER'
35
export const EMPTY_STATE = 'EMPTY_STATE'
46
export const ADD_NESTED_HTML = 'ADD_NESTED_HTML'
@@ -64,6 +66,8 @@ export const DELETE_USER_STATE = 'DELETE_USER_STATE'
6466
export const SET_IMAGE_PATH = 'SET_IMAGE_PATH'
6567

6668
// Actions
69+
export const upOneLayer = 'upOneLayer'
70+
export const addNestedNoActive ='addNestedNoActive'
6771
export const setActiveLayer = 'setActiveLayer'
6872
export const addNestedHTML = 'addNestedHTML'
6973
export const updateComponentSize = 'updateComponentSize'

0 commit comments

Comments
 (0)