Skip to content

Commit 5558178

Browse files
APAP
authored andcommitted
undo/redo working for some things but NOT BUTTONS
1 parent 2c45e13 commit 5558178

File tree

8 files changed

+151
-17
lines changed

8 files changed

+151
-17
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"aws-amplify": "^1.1.30",
2222
"aws-amplify-vue": "^0.2.13",
2323
"aws-appsync": "^1.8.1",
24-
"lodash": ">=4.17.13",
2524
"fs-extra": "^8.1.0",
2625
"localforage": "^1.7.3",
26+
"lodash": ">=4.17.13",
27+
"lodash.isequal": "^4.5.0",
2728
"mousetrap": "^1.6.3",
2829
"prismjs": "^1.16.0",
2930
"quasar": "^1.0.0",

src/App.vue

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
</template>
66

77
<script>
8+
import { SET_ACTIVE_COMPONENT } from './store/types'
9+
const deepEqual = require('lodash.isequal')
10+
811
912
let redoMixin = {
1013
data() {
1114
return {
1215
// banana:[],
1316
doneAction:[],
17+
undoneAction:[],
18+
isTimetraveling: false
1419
}
1520
},
1621
@@ -22,6 +27,19 @@ let redoMixin = {
2227
2328
this.$store.subscribeAction((action,state)=>{
2429
this.doneAction.push(action)
30+
// console.log('this is the action we are logging',action)
31+
// console.log('this is in our redo queue', this.undoneAction[this.undoneAction.length-1])
32+
// console.log("Are these equal to each other?", action == this.undoneAction[this.undoneAction.length-1])
33+
if(!this.isTimetraveling){
34+
if (this.undoneAction[this.undoneAction.length-1]){
35+
if(action.type == this.undoneAction[this.undoneAction.length-1].type && deepEqual(action.payload,this.undoneAction[this.undoneAction.length-1].payload)){
36+
this.undoneAction.pop()
37+
}
38+
else{
39+
this.undoneAction = []
40+
}
41+
}
42+
}
2543
})
2644
// this.blankState = cloneDeep(this.$store)
2745
},
@@ -33,11 +51,25 @@ let redoMixin = {
3351
this.undo()
3452
}
3553
});
54+
window.addEventListener("keyup", event => {
55+
if (event.key === "y") {
56+
this.redo()
57+
}
58+
});
3659
},
3760
3861
methods: {
3962
undo: function() {
40-
this.doneAction.pop();
63+
// do {
64+
// console.log("How far back?")
65+
let undone = this.doneAction.pop()
66+
this.isTimetraveling = true;
67+
if(undone !== undefined){
68+
this.undoneAction.push(undone)
69+
}
70+
// } while (this.doneAction[this.doneAction.length-1] &&
71+
// (this.doneAction[this.doneAction.length - 1].type === "setActiveComponent" ||
72+
// this.doneAction[this.doneAction.length - 1].type === "updateComponentPosition" ))
4173
this.$store.commit("EMPTY_STATE",this.$store)
4274
console.log(this.$store)
4375
this.doneAction.forEach(action => {
@@ -46,8 +78,23 @@ let redoMixin = {
4678
this.$store.dispatch(action.type, action.payload);
4779
this.doneAction.pop();
4880
});
81+
this.isTimetraveling = false;
4982
50-
}
83+
},
84+
redo: function() {
85+
86+
let action = this.undoneAction.pop()
87+
this.isTimetraveling = true;
88+
if(action){
89+
this.$store.dispatch(action.type, action.payload)
90+
}
91+
this.isTimetraveling = false;
92+
// if(action && (action.type === "setActiveComponent" || action.type === "updateStartingPosition")){
93+
// console.log("WE GOTTA DO MORE")
94+
// this.redo();
95+
// }
96+
}
97+
5198
}
5299
}
53100

src/components/ComponentDisplay.vue

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
@dragging="onDrag"
2020
@resizing="onResize"
2121
@dblclick.native="onDoubleClick(componentData)"
22+
@dragstop="finishedDrag"
23+
:onDragStart="recordInitialPosition"
2224
>
2325
<div class="component-title">
2426
<p>{{ componentData.componentName }}</p>
@@ -85,7 +87,8 @@ export default {
8587
testOptions: ["parent", "child", "grandchild"],
8688
testModel: [],
8789
mockImg: false,
88-
counter: 0
90+
counter: 0,
91+
initialPosition:{x:0, y:0,},
8992
};
9093
},
9194
mounted() {
@@ -205,7 +208,9 @@ export default {
205208
...mapActions([
206209
"setActiveComponent",
207210
"updateComponentChildrenMultiselectValue",
208-
"updateActiveComponentChildrenValue"
211+
"updateActiveComponentChildrenValue",
212+
"updateComponentPosition",
213+
"updateStartingPosition",
209214
]),
210215
onResize: function(x, y, width, height) {
211216
this.activeComponentData.x = x;
@@ -218,6 +223,26 @@ export default {
218223
this.componentMap[this.activeComponent].w = width;
219224
this.componentMap[this.activeComponent].h = height;
220225
},
226+
227+
recordInitialPosition: function(e) {
228+
console.log("we started a drag")
229+
console.log("this.intialPosition",this.initialPosition)
230+
console.log("WHAT IS THIS", this)
231+
if(this.activeComponent !== e.target.id){
232+
this.setActiveComponent(e.target.id)
233+
}
234+
this.initialPosition.x = this.componentMap[this.activeComponent].x
235+
this.initialPosition.y = this.componentMap[this.activeComponent].y
236+
let payload = {
237+
x: this.initialPosition.x,
238+
y: this.initialPosition.y,
239+
activeComponent: this.activeComponent,
240+
routeArray: this.routes[this.activeRoute],
241+
activeComponentData: this.activeComponentData
242+
}
243+
this.updateStartingPosition(payload);
244+
},
245+
221246
onDrag: function(x, y) {
222247
this.activeComponentData.x = x;
223248
this.activeComponentData.y = y;
@@ -226,19 +251,45 @@ export default {
226251
this.componentMap[this.activeComponent].y = y;
227252
this.userImage;
228253
},
229-
onLayer: function(z) {
230-
this.activeComponentData.z = z;
254+
// onLayer: function(z) {
255+
// this.activeComponentData.z = z;
256+
// // Want to change the "Z" of the component found in Routes[activeRoute][whatever the component is]
257+
// //have to do this via an action or it won't be preserved in our undo/redo
258+
// },
259+
260+
finishedDrag: function(x,y){
261+
console.log("FINISHED DRAGGING")
262+
let payload = {
263+
x: x,
264+
y: y,
265+
activeComponent: this.activeComponent,
266+
routeArray: this.routes[this.activeRoute],
267+
activeComponentData: this.activeComponentData
268+
}
269+
console.log("Payload.x = ", payload.x, "this.initialPosition.x", this.initialPosition.x)
270+
console.log("Payload.y = ", payload.y, "this.initialPosition.y", this.initialPosition.y)
271+
if(payload.x !== this.initialPosition.x || payload.y !== this.initialPosition.y){
272+
this.updateComponentPosition(payload);
273+
}
231274
},
275+
232276
onActivated(componentData) {
277+
console.log("I RAN!")
233278
this.$refs.boxes.forEach((element)=> {
234279
if (element.$attrs.id !== componentData.componentName){
235280
element.enabled = false;
236281
element.$emit('deactivated')
237282
element.$emit('update:active', false)
238283
}
239284
})
240-
this.setActiveComponent(componentData.componentName);
285+
// console.log("this is what is currently active",this.activeComponent)
286+
// console.log("this is this", this)
287+
// console.log('!(componentData.componentName === this.activeComponent)?',!(componentData.componentName === this.activeComponent))
288+
if(!(componentData.componentName === this.activeComponent)){
289+
this.setActiveComponent(componentData.componentName);
290+
}
241291
this.activeComponentData.isActive = true;
292+
242293
243294
},
244295
@@ -256,7 +307,9 @@ export default {
256307
// }
257308
},
258309
onDoubleClick(compData) {
259-
this.setActiveComponent(compData.componentName);
310+
if(!(componentData.componentName === this.activeComponent)){
311+
this.setActiveComponent(componentData.componentName);
312+
}
260313
this.activeComponentData.isActive = true;
261314
},
262315
handleAddChild() {
@@ -294,7 +347,9 @@ export default {
294347
handleClick(event){
295348
if(event.target.className === "component-display grid-bg")
296349
{
297-
this.setActiveComponent('')
350+
if(!('' === this.activeComponent)){
351+
this.setActiveComponent('');
352+
}
298353
}
299354
}
300355
}

src/components/CreateComponent.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export default {
8484
8585
},
8686
resetActiveComponent () {
87+
if(!this.activeComponent === ''){
8788
this.setActiveComponent('')
89+
}
8890
8991
},
9092
handleIconClick () {

src/store/actions.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ const actions = {
5050
commit(types.SET_SELECTED_ELEMENT_LIST, payload)
5151
}
5252
},
53+
54+
[types.updateComponentPosition]: ({ commit }, payload) =>{
55+
/* let payload = {
56+
x = x,
57+
y = y,
58+
activeComponent = this.activeComponent,
59+
routeArray = this.routes[this.activeRoute],
60+
activeComponentData = this.activeComponentData
61+
}*/
62+
63+
commit(types.UPDATE_COMPONENT_POSITION, payload)
64+
65+
},
66+
67+
//does the same as update component position, but needed to record the initial spot of the draggable resizeable in component display
68+
// or else undo/redo won't work
69+
[types.updateStartingPosition]: ({ commit }, payload) => {
70+
commit(types.UPDATE_COMPONENT_POSITION, payload)
71+
},
72+
73+
5374
// adds component to the homeQueue
5475
[types.addToSelectedElementList]: ({ commit }, payload) => {
5576
commit(types.ADD_TO_SELECTED_ELEMENT_LIST, payload)

src/store/mutations.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as types from './types'
22
import icons from './state/icons.js'
33
import htmlElementMap from './state/htmlElementMap.js'
44
// import VuexStore from './index'
5-
//import { getDefault, defaultState } from './state/index.js'
5+
// import { getDefault, defaultState } from './state/index.js'
66

77
import localforage from 'localforage'
88

9-
const defaultState =
9+
const defaultState =
1010
{
1111
icons,
1212
htmlElementMap,
@@ -47,9 +47,6 @@ const defaultState =
4747
imagePath: ''
4848
}
4949

50-
51-
52-
5350
const mutations = {
5451
// pushs new component to componentMap
5552
[types.ADD_COMPONENT_TO_COMPONENT_MAP]: (state, payload) => {
@@ -123,8 +120,7 @@ const mutations = {
123120
modalOpen: false,
124121
parentSelected: false,
125122
imagePath: ''
126-
});
127-
123+
})
128124
},
129125

130126
// add parent
@@ -275,6 +271,10 @@ const mutations = {
275271
const { component, value } = payload
276272
state.componentMap[component].children = value
277273
},
274+
[types.UPDATE_COMPONENT_POSITION]: (state, payload) => {
275+
payload.activeComponentData.x = payload.x
276+
payload.activeComponentData.y = payload.y //Object.assign({}, state.componentMap[payload.activeComponent], {x: payload.x, y: payload.y});
277+
},
278278
[types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE]: (state, payload) => {
279279
// original line
280280
let temp = state.componentMap[state.activeComponent].children // b c and we are removing c

src/store/types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const UPDATE_COMPONENT_NAME_INPUT_VALUE =
3434
'UPDATE_COMPONENT_NAME_INPUT_VALUE'
3535
export const UPDATE_COMPONENT_CHILDREN_VALUE =
3636
'UPDATE_COMPONENT_CHILDREN_VALUE'
37+
export const UPDATE_COMPONENT_POSITION = "UPDATE_COMPONENT_POSITION"
3738
export const UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE =
3839
'UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE'
3940
export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
@@ -76,6 +77,7 @@ export const incrementProjectId = 'incrementProjectId'
7677
export const setRoutes = 'setRoutes'
7778
export const setComponentHtmlList = 'setComponentHtmlList'
7879
export const deleteProjectTab = 'deleteProjectTab'
80+
export const updateStartingPosition = 'updateStartingPosition'
7981
// ChildrenMultiselect actions
8082
export const updateComponentChildrenMultiselectValue =
8183
'updateComponentChildrenMultiselectValue'
@@ -84,6 +86,7 @@ export const updateActiveComponentChildrenValue =
8486

8587
export const updateComponentChildrenValue = 'updateComponentChildrenValue'
8688
export const updateComponentNameInputValue = 'updateComponentNameInputValue'
89+
export const updateComponentPosition = 'updateComponentPosition'
8790
export const updateOpenModal = 'updateOpenModal'
8891
export const parentSelected = 'parentSelected'
8992
export const deleteRoute = 'deleteRoute'

0 commit comments

Comments
 (0)