Skip to content

Commit 20807bf

Browse files
Merge pull request #29 from oslabs-beta/bryan/displayRoutesOnTutorialClose
Bryan/display routes on tutorial close
2 parents a334f66 + c4d1c4a commit 20807bf

File tree

11 files changed

+147
-162
lines changed

11 files changed

+147
-162
lines changed

src/components/ComponentDisplay.vue

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class="component-display grid-bg"
1111
:style="mockBg"
1212
v-on:click="handleClick"
13+
v-on:click.right="handleRight"
1314
>
1415
<!-- This is the actual component box -->
1516
<!-- https://www.npmjs.com/package/vue-draggable-resizable -->
@@ -50,7 +51,7 @@
5051
<q-menu context-menu>
5152
<q-list color="black" class="menu">
5253
<q-item clickable v-ripple v-close-popup id="layer-item">
53-
<q-item-section class="layer">Layer</q-item-section>
54+
<q-item-section class="layer">Component Layer</q-item-section>
5455
<q-btn
5556
class="minorAction"
5657
color="transparent"
@@ -91,19 +92,22 @@
9192
</vue-draggable-resizable>
9293
<div>
9394
<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-
/>
95+
<div class="addChild">
96+
<p>Add/Remove Children</p>
97+
<VueMultiselect
98+
v-model="childrenSelected"
99+
placeholder="Add/remove children"
100+
:multiple="true"
101+
:close-on-select="false"
102+
:options="options"
103+
:show-labels="false"
104+
@remove="handleSelect"
105+
@select="handleSelect"
106+
:height="300"
107+
:option-height="40"
108+
:searchable="false"
109+
/>
110+
</div>
107111
</q-dialog>
108112

109113
<!-- 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 +157,7 @@
153157
<script>
154158
import { mapState, mapActions } from "vuex";
155159
import VueDraggableResizable from "vue-draggable-resizable/src/components/vue-draggable-resizable.vue";
160+
import VueMultiselect from "vue-multiselect";
156161
import "vue-draggable-resizable/src/components/vue-draggable-resizable.css";
157162
import handleExportComponentMixin from "./ExportComponentMixin.vue";
158163
const { fs, ipcRenderer } = window;
@@ -163,6 +168,7 @@ export default {
163168
name: "ComponentDisplay",
164169
components: {
165170
VueDraggableResizable,
171+
VueMultiselect,
166172
},
167173
mixins: [handleExportComponentMixin],
168174
data() {
@@ -176,6 +182,7 @@ export default {
176182
initialPosition: { x: 0, y: 0 },
177183
initialSize: { w: 0, h: 0 },
178184
htmlElements: [],
185+
childrenSelected: [],
179186
};
180187
},
181188
mounted() {
@@ -203,7 +210,7 @@ export default {
203210
});
204211
window.addEventListener("paste", () => {
205212
if (this.noteModalOpen === false){
206-
this.$store.dispatch("pasteActiveComponent");
213+
this.$store.dispatch("pasteActiveComponent");
207214
}
208215
});
209216
},
@@ -217,8 +224,8 @@ export default {
217224
"imagePath",
218225
"activeComponentObj",
219226
"exportAsTypescript",
220-
"noteModalOpen"
221-
227+
"noteModalOpen",
228+
"activeRouteDisplay"
222229
]),
223230
// used in VueDraggableResizeable component
224231
activeRouteArray() {
@@ -231,34 +238,37 @@ export default {
231238
return cloneDeep(this.activeComponentObj);
232239
},
233240
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]);
241+
if (this.activeComponent !== ''){
242+
this.childrenSelected = [];
243+
this.childrenSelected = this.componentMap[this.activeComponent].children;
244+
} else {
245+
this.childrenSelected = [];
251246
}
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-
});
247+
const compMap = this.componentMap;
248+
const activeComp = this.activeComponent;
249+
const val = this.routes[this.activeRoute].map(
250+
(component) => component.componentName
251+
);
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];
@@ -316,7 +326,6 @@ export default {
316326
recordInitialPosition: function (e) {
317327
if (this.activeComponent !== e.target.id) {
318328
if (e.target.parentElement?.classList.contains('draggable')){
319-
//console.log("using vanilla JS to WIN")
320329
this.setActiveComponent(e.target.parentElement.id)
321330
} else {
322331
this.setActiveComponent(e.target.id);
@@ -424,7 +433,7 @@ export default {
424433
this.deleteActiveComponentNote(e.target.previousElementSibling.innerText);
425434
},
426435
// used when user selects to add child from dropdown
427-
handleSelect(value) {
436+
handleSelect(value) { //actually handles adding or deleting
428437
this.updateActiveComponentChildrenValue(value);
429438
},
430439
// user can change component's layer order
@@ -446,7 +455,11 @@ export default {
446455
this.setActiveComponent("");
447456
}
448457
},
449-
copyActiveComponent() {},
458+
handleRight(event) {
459+
if (event.target.className === "component-display grid-bg") {
460+
//right click modal to make a component?
461+
}
462+
},
450463
},
451464
watch: {
452465
noteModalOpen (){
@@ -468,6 +481,17 @@ export default {
468481
</script>
469482
470483
<style scoped lang="scss">
484+
485+
.addChild{
486+
width: 25vh;
487+
height: 50vh;
488+
display: flex;
489+
flex-direction: column;
490+
align-items: center;
491+
background: $subsecondary;
492+
padding: 10px;
493+
}
494+
471495
li{
472496
display: flex;
473497
font-weight: bold;
@@ -477,6 +501,8 @@ li{
477501
li:hover{
478502
background-color: $subprimary;
479503
}
504+
505+
480506
.noteblock{
481507
white-space: pre-wrap;
482508
font-weight: normal;

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import "prismjs/themes/prism-tomorrow.css"; // import syntax highlighting styles
3535
export default {
3636
data() {
3737
return {
38-
// code: `Your component boilerplate will be displayed here.`,
38+
code: `Your component boilerplate will be displayed here.`,
3939
lineNumbers: true,
4040
height: null,
4141
};
@@ -46,18 +46,19 @@ export default {
4646
computed: {
4747
// needs access to current component aka activeComponent
4848
...mapState(["componentMap", "activeComponent", "activeComponentObj", "exportAsTypescript"]),
49-
code: function () {
50-
let computedCode = "Your component boilerplate will be displayed here.";
51-
if (this.activeComponent) {
52-
computedCode = this.createCodeSnippet(
49+
},
50+
methods: {
51+
snippetInvoke(){
52+
if (this.activeComponent !== ''){
53+
this.code = this.createCodeSnippet(
5354
this.componentMap[this.activeComponent].componentName,
5455
this.componentMap[this.activeComponent].children
55-
);
56+
)
57+
} else {
58+
this.code = 'Your component boilerplate will be displayed here.'
5659
}
57-
return computedCode;
5860
},
59-
},
60-
methods: {
61+
//highlighter does not work: OverVue 6.0;
6162
highlighter(myCode) {
6263
return highlight(myCode, languages.js);
6364
},
@@ -161,16 +162,16 @@ export default {
161162
// add import mapstate and mapactions if they exist
162163
let imports = "";
163164
if (
164-
this.activeComponentObj.actions.length ||
165-
this.activeComponentObj.state.length
165+
this.componentMap[this.activeComponent].actions.length ||
166+
this.componentMap[this.activeComponent].state.length
166167
) {
167168
imports += "import { ";
168169
if (
169-
this.activeComponentObj.actions.length &&
170-
this.activeComponentObj.state.length
170+
this.componentMap[this.activeComponent].actions.length &&
171+
this.componentMap[this.activeComponent].state.length
171172
) {
172173
imports += "mapState, mapActions";
173-
} else if (this.activeComponentObj.state.length) imports += "mapState";
174+
} else if (this.componentMap[this.activeComponent].state.length) imports += "mapState";
174175
else imports += "mapActions";
175176
imports += ' } from "vuex";\n';
176177
}
@@ -193,9 +194,9 @@ export default {
193194
194195
// if true add data section and populate with props
195196
let data = "";
196-
if (this.activeComponentObj.props.length) {
197+
if (this.componentMap[this.activeComponent].props.length) {
197198
data += " data () {\n return {";
198-
this.activeComponentObj.props.forEach((prop) => {
199+
this.componentMap[this.activeComponent].props.forEach((prop) => {
199200
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`;
200201
});
201202
data += "\n";
@@ -205,10 +206,10 @@ export default {
205206
206207
// if true add computed section and populate with state
207208
let computed = "";
208-
if (this.activeComponentObj.state.length) {
209+
if (this.componentMap[this.activeComponent].state.length) {
209210
computed += " computed: {";
210211
computed += "\n ...mapState([";
211-
this.activeComponentObj.state.forEach((state) => {
212+
this.componentMap[this.activeComponent].state.forEach((state) => {
212213
computed += `\n "${state}",`;
213214
});
214215
computed += "\n ]),\n";
@@ -217,10 +218,10 @@ export default {
217218
218219
// if true add methods section and populate with actions
219220
let methods = "";
220-
if (this.activeComponentObj.actions.length) {
221+
if (this.componentMap[this.activeComponent].actions.length) {
221222
methods += " methods: {";
222223
methods += "\n ...mapActions([";
223-
this.activeComponentObj.actions.forEach((action) => {
224+
this.componentMap[this.activeComponent].actions.forEach((action) => {
224225
methods += `\n "${action}",`;
225226
});
226227
methods += "\n ]),\n";
@@ -249,40 +250,29 @@ export default {
249250
} else {
250251
output += "};\n<\/script>\n\n<style scoped>\n</style>"
251252
}
252-
// eslint-disable-next-line no-useless-escape
253-
// add props/data
254-
255-
// eslint-disable-next-line no-useless-escape
256-
// return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n
257-
// components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n
258-
// </style>`
259253
return output;
260254
},
261255
},
262256
watch: {
263-
// // watches activeComponentObj for changes to make it reactive upon mutation
264-
// activeComponentObj: {
265-
// handler () {
266-
// // console.log(this.activeComponentObj.children)
267-
// this.code = this.createCodeSnippet(
268-
// this.activeComponentObj.componentName,
269-
// this.activeComponentObj.children
270-
// )
271-
// }
272-
// },
273-
// // // // watches componentMap for changes to make it reactive upon mutation
274-
// componentMap: {
275-
// handler () {
276-
// this.code = this.createCodeSnippet(
277-
// this.activeComponentObj.componentName,
278-
// this.activeComponentObj.children
279-
// )
280-
// }
281-
// }
257+
// watches activeComponentObj for changes to make it reactive upon mutation
258+
// // // watches componentMap for changes to make it reactive upon mutation
259+
activeComponent: {
260+
handler () {
261+
this.snippetInvoke();
262+
},
263+
deep: true
264+
},
265+
componentMap: {
266+
handler () {
267+
this.snippetInvoke();
268+
},
269+
deep: true
270+
}
282271
},
283272
mounted() {
284273
// https://vuejs.org/v2/api/#Vue-nextTick
285274
// kinda like a promise, used for the window resize
275+
this.snippetInvoke(); //generates the code snippet whenever this is mounted
286276
this.$nextTick(() => {
287277
window.addEventListener("resize", this.getWindowHeight);
288278
@@ -304,15 +294,18 @@ export default {
304294
font-size: 12px;
305295
background: #2d2d2d;
306296
color: #ccc;
307-
max-height: 70vh;
297+
max-height: 100%;
308298
/* you must provide font-family font-size line-height. Example: */
309299
font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace;
310300
line-height: 1.5;
311301
padding: 5px;
312302
}
313303
314304
.codesnippet-container {
315-
margin-bottom: 1rem;
305+
padding-bottom: 1rem;
306+
padding-left: 1rem;
307+
padding-right: 1rem;
308+
height: 95%;
316309
}
317310
318311
.prism-editor__textarea:focus {

0 commit comments

Comments
 (0)