Skip to content

Commit 55d1def

Browse files
committed
WE CAN GO DEEPER
1 parent a3fdd6b commit 55d1def

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let redoMixin = {
6666
if (event.ctrlKey && event.key === 'a') {
6767
event.preventDefault()
6868
if (this.$store.state.activeHTML !== '') {
69-
this.$store.dispatch('addNestedHTML', { elementName: 'div', date: Date.now() })
69+
this.$store.dispatch('setActiveLayer', this.$store.state.activeHTML)
7070
}
7171
}
7272
});

src/components/HomeQueue.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,21 @@
2424
import draggable from 'vuedraggable'
2525
import { mapState, mapActions } from 'vuex'
2626
import { setSelectedElementList, deleteSelectedElement, deleteFromComponentHtmlList, setActiveHTML } from '../store/types'
27-
27+
const breadthFirstSearch = (array,id) => {
28+
let queue = [...array.filter(el => typeof el === 'object')];
29+
while(queue.length){
30+
let evaluated = queue.shift()
31+
if(evaluated.id === id){
32+
return evaluated
33+
}
34+
else{
35+
if (evaluated.children.length){
36+
queue.push(...evaluated.children)
37+
}
38+
}
39+
}
40+
console.log("We shouldn't be ever getting here, how did you even search an id that didn't exist?")
41+
}
2842
export default {
2943
name: 'HomeQueue',
3044
props: {
@@ -41,15 +55,23 @@ export default {
4155
// }
4256
// },
4357
computed: {
44-
...mapState(['selectedElementList', 'componentMap', 'activeComponent', 'activeHTML']),
58+
...mapState(['selectedElementList', 'componentMap', 'activeComponent', 'activeHTML','activeLayer']),
4559
renderList: {
4660
get () {
4761
if (this.activeComponent === '') return this.selectedElementList.map((el, index) => [el.text, index, el.id])
48-
// change activeComponent's htmlList into an array of arrays ([element/component name, index in state])
49-
let sortedHTML = this.componentMap[this.activeComponent].htmlList.map((el, index) => [el.text, index, el.id]).filter(el => {
50-
return el[0] !== undefined
51-
})
52-
return sortedHTML
62+
// change activeComponent's htmlList into an array of arrays ([element/component name, index in state])
63+
if (this.activeComponent !== '' && this.activeLayer.id === '') {
64+
console.log('this works right?')
65+
let sortedHTML = this.componentMap[this.activeComponent].htmlList.map((el, index) => [el.text, index, el.id]).filter(el => {
66+
return el[0] !== undefined
67+
})
68+
return sortedHTML
69+
}
70+
let activeElement = breadthFirstSearch(this.componentMap[this.activeComponent].htmlList, this.activeLayer.id)
71+
let sortedHTML = activeElement.children.map((el, index) => [el.text, index, el.id]).filter(el => {
72+
return el[0] !== undefined
73+
})
74+
return sortedHTML
5375
},
5476
set (value) {
5577
this.$store.dispatch(setSelectedElementList, value)

src/store/actions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const actions = {
88
// },
99

1010
// creates a new component in componentMap
11+
12+
[types.setActiveLayer]: ({commit}, payload) => {
13+
commit(types.SET_ACTIVE_LAYER, payload)
14+
},
15+
1116
[types.registerComponent]: ({ state, commit }, payload) => {
1217
const { componentName } = payload
1318
if (!state.componentMap[componentName]) {

src/store/mutations.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ const breadthFirstSearchParent = (array,id) => {
4343
}
4444

4545
const mutations = {
46+
47+
[types.SET_ACTIVE_LAYER]: (state, payload) =>{
48+
let newLayer = cloneDeep(state.activeLayer)
49+
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+
if(newLayer.id === ''){
60+
newLayer.lineage.push(state.activeComponent)
61+
}
62+
else{
63+
newLayer.lineage.push(newLayer.id)
64+
}
65+
newLayer.id = payload
66+
}
67+
state.activeLayer = newLayer
68+
},
69+
70+
4671
// pushs new component to componentMap
4772
[types.ADD_COMPONENT_TO_COMPONENT_MAP]: (state, payload) => {
4873
const { componentName, htmlList, children, parent, isActive } = payload

src/store/state/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const newState = {
6969
lineage:[]
7070
},
7171

72-
7372
selectedElementList: [],
7473
projectNumber: 2,
7574
activeTab: 0,

src/store/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Mutations
2+
export const SET_ACTIVE_LAYER = 'SET_ACTIVE_LAYER'
23
export const EMPTY_STATE = 'EMPTY_STATE'
34
export const ADD_NESTED_HTML = 'ADD_NESTED_HTML'
45
export const ADD_COMPONENT_TO_COMPONENT_MAP = 'ADD_COMPONENT_TO_COMPONENT_MAP'
@@ -63,6 +64,7 @@ export const DELETE_USER_STATE = 'DELETE_USER_STATE'
6364
export const SET_IMAGE_PATH = 'SET_IMAGE_PATH'
6465

6566
// Actions
67+
export const setActiveLayer = 'setActiveLayer'
6668
export const addNestedHTML = 'addNestedHTML'
6769
export const updateComponentSize = 'updateComponentSize'
6870
export const updateStartingSize = 'updateStartingSize'

0 commit comments

Comments
 (0)