Skip to content

Commit add8562

Browse files
Shanon LeeShanon Lee
authored andcommitted
Fix bugs MyLayout.vue. deprecated in Vue3. Instead, use emit and props to communicate between App.vue & MyLayout.vue for UNDO/REDO functionality
1 parent 12ce276 commit add8562

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/App.vue

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22
<template>
3-
<router-view />
3+
<!-- Get passed down to MyLayout.vue
4+
& listen for custom events emitted from MyLayout.vue -->
5+
<router-view
6+
v-on:undo="undoTrigger"
7+
v-on:redo="redoTrigger"
8+
v-bind:done-action="doneAction"
9+
v-bind:undone-action="undoneAction"
10+
/>
411
</template>
512

613
<script>
@@ -25,7 +32,8 @@ let redoMixin = {
2532
doneAction: [],
2633
undoneAction: [],
2734
isTimetraveling: false,
28-
initialState: {}
35+
initialState: {},
36+
doneActionLength: 0
2937
}
3038
},
3139
created () {
@@ -35,7 +43,8 @@ let redoMixin = {
3543
// console.log("We saved the world with a deepclone!", action.payload === cloneDeep)
3644
action.payload = cloneDeep(action.payload)
3745
}
38-
this.doneAction.push(action)
46+
this.doneAction.push(action);
47+
// console.log(`From app.vue: ${action.payload}`)
3948
// console.log('this is the action we are logging',action)
4049
// console.log('this is in our redo queue', this.undoneAction[this.undoneAction.length-1])
4150
// console.log("Are these equal to each other?", action == this.undoneAction[this.undoneAction.length-1])
@@ -87,7 +96,6 @@ let redoMixin = {
8796
}
8897
8998
this.isTimetraveling = true
90-
9199
let undone = this.doneAction.pop()
92100
93101
/* assuming we have have something to undo, we check if we are undoing an action that has no feedback
@@ -140,6 +148,18 @@ let redoMixin = {
140148
// console.log('in the redo loop')
141149
this.redo()
142150
}
151+
},
152+
153+
// Undo triggered from MyLayout.vue
154+
undoTrigger: function() {
155+
const throttledUndo = throttle(this.undo, 300);
156+
throttledUndo();
157+
},
158+
159+
// Redo triggered from MyLayout.vue
160+
redoTrigger: function() {
161+
const throttledRedo = throttle(this.redo, 300);
162+
throttledRedo();
143163
}
144164
}
145165
}

src/layouts/MyLayout.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Description:
2020
<q-toolbar-title> OverVue </q-toolbar-title>
2121
<SlackLoginWindow />
2222
<div></div>
23-
<!-- <i
24-
v-if="this.$router.app.$children[0].doneAction.length"
23+
<i v-if="doneAction.length"
2524
class="fa fa-backward"
2625
aria-hidden="true"
2726
@click="undo"
@@ -31,14 +30,15 @@ Description:
3130
class="fa fa-backward"
3231
id="unavailable"
3332
aria-hidden="true"
34-
></i> -->
35-
<!-- <i
36-
v-if="this.$router.app.$children[0].undoneAction.length"
33+
></i>
34+
<i
35+
v-if="undoneAction.length"
3736
class="fa fa-forward"
3837
aria-hidden="true"
3938
@click="redo"
4039
></i>
41-
<i v-else class="fa fa-forward" id="unavailable" aria-hidden="true"></i> -->
40+
<i v-else class="fa fa-forward" id="unavailable" aria-hidden="true"></i>
41+
4242
<!-- <OpenProjectComponent /> -->
4343
<SaveProjectComponent />
4444
<ExportProjectComponent />
@@ -116,6 +116,8 @@ import SlackLoginWindow from "../components/slack_login/SlackLoginWindow.vue";
116116
import StoreTab from "../components/home_sidebar_items/StoreTab/StoreTab.vue";
117117
118118
export default {
119+
// Passed down from App.vue
120+
props: ['doneAction', 'undoneAction'],
119121
data() {
120122
return {
121123
tab: "component",
@@ -139,11 +141,16 @@ export default {
139141
undo() {
140142
// console.log('UNDO FROM BUTTON')
141143
// console.log('look at me ', this.$router.app.$children[0].doneAction)
142-
this.$router.app.$children[0].undo();
144+
// this.$router.app.$children[0].undo();
145+
// console.log(this.doneAction);
146+
// Emit custom event, listen in App.vue to trigger undo or redo
147+
this.$emit('undo');
143148
},
144149
redo() {
145150
// console.log('REDO FROM BUTTON')
146-
this.$router.app.$children[0].redo();
151+
// this.$router.app.$children[0].redo();
152+
this.$emit('redo');
153+
console.log('redo')
147154
},
148155
},
149156
};

0 commit comments

Comments
 (0)