Skip to content

Commit a16e548

Browse files
committed
paste throttle added to hopefully mitigate the problemw ith components pasting too quickly. fixed add children right click modal on active component to display children and allow selection/deselection
1 parent 30e8c11 commit a16e548

File tree

5 files changed

+78
-45
lines changed

5 files changed

+78
-45
lines changed

src/components/ComponentDisplay.vue

Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<q-menu context-menu>
5151
<q-list color="black" class="menu">
5252
<q-item clickable v-ripple v-close-popup id="layer-item">
53-
<q-item-section class="layer">Layer</q-item-section>
53+
<q-item-section class="layer">Component Layer</q-item-section>
5454
<q-btn
5555
class="minorAction"
5656
color="transparent"
@@ -91,19 +91,22 @@
9191
</vue-draggable-resizable>
9292
<div>
9393
<q-dialog v-model="modalOpen">
94-
<q-select
95-
@select="handleSelect"
96-
id="childrenDropdown"
97-
filled
98-
v-model="testModel"
99-
multiple
100-
:options="options"
101-
use-chips
102-
stack-label
103-
dark
104-
label="Select children"
105-
style="width: 250px; background-color: #201221;"
106-
/>
94+
<div class="addChild">
95+
<p>Add/Remove Children</p>
96+
<VueMultiselect
97+
v-model="childrenSelected"
98+
placeholder="Add/remove children"
99+
:multiple="true"
100+
:close-on-select="false"
101+
:options="options"
102+
:show-labels="false"
103+
@remove="handleSelect"
104+
@select="handleSelect"
105+
:height="300"
106+
:option-height="40"
107+
:searchable="false"
108+
/>
109+
</div>
107110
</q-dialog>
108111

109112
<!-- some irregularity (delete event listener firing on bkspc/del) with the modal when stored locally, so modal open stored in state, and triggers to local reflect only stateful change.-->
@@ -153,6 +156,7 @@
153156
<script>
154157
import { mapState, mapActions } from "vuex";
155158
import VueDraggableResizable from "vue-draggable-resizable/src/components/vue-draggable-resizable.vue";
159+
import VueMultiselect from "vue-multiselect";
156160
import "vue-draggable-resizable/src/components/vue-draggable-resizable.css";
157161
import handleExportComponentMixin from "./ExportComponentMixin.vue";
158162
const { fs, ipcRenderer } = window;
@@ -163,6 +167,7 @@ export default {
163167
name: "ComponentDisplay",
164168
components: {
165169
VueDraggableResizable,
170+
VueMultiselect,
166171
},
167172
mixins: [handleExportComponentMixin],
168173
data() {
@@ -176,6 +181,7 @@ export default {
176181
initialPosition: { x: 0, y: 0 },
177182
initialSize: { w: 0, h: 0 },
178183
htmlElements: [],
184+
childrenSelected: [],
179185
};
180186
},
181187
mounted() {
@@ -203,7 +209,7 @@ export default {
203209
});
204210
window.addEventListener("paste", () => {
205211
if (this.noteModalOpen === false){
206-
this.$store.dispatch("pasteActiveComponent");
212+
this.$store.dispatch("pasteActiveComponent");
207213
}
208214
});
209215
},
@@ -217,8 +223,8 @@ export default {
217223
"imagePath",
218224
"activeComponentObj",
219225
"exportAsTypescript",
220-
"noteModalOpen"
221-
226+
"noteModalOpen",
227+
"activeRouteDisplay"
222228
]),
223229
// used in VueDraggableResizeable component
224230
activeRouteArray() {
@@ -231,34 +237,38 @@ export default {
231237
return cloneDeep(this.activeComponentObj);
232238
},
233239
options() {
234-
// checks if component has any parents and pushes them into lineage
235-
const checkParents = (component, lineage = [component.componentName]) => {
236-
console.log("Lineage: " + lineage);
237-
if (!Object.keys(component.parent).length) return lineage;
238-
for (var parents in component.parent) {
239-
// Mutating?
240-
lineage.push(parents);
241-
checkParents(component.parent[parents], lineage);
242-
}
243-
return lineage;
244-
};
245-
let lineage = [this.activeComponent];
246-
// checks to see if there are any existing children
247-
if (this.componentMap[this.activeComponent]) {
248-
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
249-
this.testModel = this.componentMap[this.activeComponent].children;
250-
lineage = checkParents(this.componentMap[this.activeComponent]);
240+
if (this.activeComponent !== ''){
241+
this.childrenSelected = [];
242+
this.childrenSelected = this.componentMap[this.activeComponent].children;
243+
} else {
244+
this.childrenSelected = [];
251245
}
252-
const routes = Object.keys(this.routes);
253-
const exceptions = new Set([
254-
"App",
255-
...lineage,
256-
...routes,
257-
...this.testModel,
258-
]);
259-
return Object.keys(this.componentMap).filter((component) => {
260-
if (!exceptions.has(component)) return component;
261-
});
246+
const compMap = this.componentMap;
247+
const activeComp = this.activeComponent;
248+
const val = this.routes[this.activeRoute].map(
249+
(component) => component.componentName
250+
);
251+
console.log(val)
252+
const relatives = [...val]
253+
//also need to filter out any parents
254+
255+
let parentalLineage = [];
256+
findLineage(relatives)
257+
function findLineage(children){
258+
children.forEach((el)=>{
259+
parentalLineage.push(el);
260+
if (compMap[el].children.length > 0){
261+
findLineage(compMap[el].children);
262+
}
263+
if (el !== activeComp){
264+
parentalLineage.pop();
265+
} else {
266+
return;
267+
}
268+
})
269+
}
270+
const optionOutput = val.filter(el => !parentalLineage.includes(el)).filter(el => el !== this.activeComponent);
271+
return optionOutput;
262272
},
263273
userImage() {
264274
const imgSrc = `file://` + this.imagePath[this.activeRoute];
@@ -424,7 +434,7 @@ export default {
424434
this.deleteActiveComponentNote(e.target.previousElementSibling.innerText);
425435
},
426436
// used when user selects to add child from dropdown
427-
handleSelect(value) {
437+
handleSelect(value) { //actually handles adding or deleting
428438
this.updateActiveComponentChildrenValue(value);
429439
},
430440
// user can change component's layer order
@@ -468,6 +478,17 @@ export default {
468478
</script>
469479
470480
<style scoped lang="scss">
481+
482+
.addChild{
483+
width: 25vh;
484+
height: 25vh;
485+
display: flex;
486+
flex-direction: column;
487+
align-items: center;
488+
background: $subsecondary;
489+
padding: 10px;
490+
}
491+
471492
li{
472493
display: flex;
473494
font-weight: bold;
@@ -477,6 +498,8 @@ li{
477498
li:hover{
478499
background-color: $subprimary;
479500
}
501+
502+
480503
.noteblock{
481504
white-space: pre-wrap;
482505
font-weight: normal;

src/store/actions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ const actions = {
108108
if (!state.copiedComponent.componentName){
109109
return
110110
}
111+
if (Date.now() < state.pasteTimer){
112+
return;
113+
} else {
114+
commit(types.UPDATE_PASTE_TIMER) //throttles pasting
115+
}
111116
commit(types.PASTE_ACTIVE_COMPONENT);
112117
// if no other parents, update as parent of active route in componentMap
113118
if (!Object.keys(state.pastedComponent.parent).length) {

src/store/mutations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ const mutations = {
288288
// reset the number of copies created
289289
state.copyNumber = 0;
290290
},
291+
[types.UPDATE_PASTE_TIMER]: (state) => {
292+
state.pasteTimer = Date.now() + 1000;
293+
},
291294

292295
[types.PASTE_ACTIVE_COMPONENT]: (state) => {
293296
// check if copied exists

src/store/state/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const newState = {
6060
exportAsTypescript: 'off',
6161
showTutorial: true,
6262
tutorialFirstOpen: true,
63+
pasteTimer: 0,
6364
}
6465

6566
// closured method to ensure we only ever write the default state ONCE

src/store/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const ADD_ACTIVE_COMPONENT_NOTE = 'ADD_ACTIVE_COMPONENT_NOTE'
6868
export const DELETE_ACTIVE_COMPONENT_NOTE = 'DELETE_ACTIVE_COMPONENT_NOTE'
6969
export const OPEN_NOTE_MODAL = 'OPEN_NOTE_MODAL'
7070
export const REMOVE_ALL_STATE_PROPS_ACTIONS = 'REMOVE_ALL_STATE_PROPS_ACTIONS'
71+
export const UPDATE_PASTE_TIMER = 'UPDATE_PASTE_TIMER'
7172

7273
// Actions
7374
export const openNoteModal = 'openNoteModal'

0 commit comments

Comments
 (0)