Skip to content

Commit fafa3c8

Browse files
committed
Merge branch 'typescript' of https://github.com/oslabs-beta/OverVue into typescript
2 parents 0356370 + c889d5f commit fafa3c8

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

src/components/composables/useExportComponent.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { openHtmlElementMap } from "src/store/state/htmlElementMap";
2-
import path from "path";
2+
import { useStore } from "src/store/main";
33
export function useExportComponent() {
44
// OVERVUE 8.0: export active component
55
/**
@@ -9,6 +9,8 @@ export function useExportComponent() {
99
* @return: none -- outputs file to fs
1010
*
1111
*/
12+
const { ipcRenderer, fs, path } = window;
13+
const store = useStore();
1214

1315
const exportComponent = () => {
1416
ipcRenderer
@@ -17,7 +19,10 @@ export function useExportComponent() {
1719
message: "Choose location to save folder in",
1820
nameFieldLabel: "Component Name",
1921
})
20-
.then((result) => exportComponentFile(result.filePath))
22+
.then((result) => {
23+
exportComponentFile(result.filePath);
24+
alert("Successfully Exported");
25+
})
2126
.catch((err) => console.log(err));
2227
};
2328

@@ -167,7 +172,7 @@ export function useExportComponent() {
167172
return nestedString;
168173
};
169174
// iterate through component's htmllist
170-
let htmlArr = this.componentMap[componentName].htmlList;
175+
let htmlArr = store.componentMap[componentName].htmlList;
171176
let outputStr = ``;
172177
// eslint-disable-next-line no-unused-vars
173178
for (let el of htmlArr) {
@@ -199,9 +204,9 @@ export function useExportComponent() {
199204
};
200205

201206
const writeComments = (componentName) => {
202-
if (this.componentMap[componentName]?.noteList?.length > 0) {
207+
if (store.componentMap[componentName]?.noteList?.length > 0) {
203208
let commentStr = "<!--";
204-
this.componentMap[componentName].noteList.forEach((el) => {
209+
store.componentMap[componentName].noteList.forEach((el) => {
205210
commentStr += "\n";
206211
commentStr += el;
207212
});
@@ -222,29 +227,29 @@ export function useExportComponent() {
222227

223228
//used to loop through - and apply class/id in code snippet
224229
if (
225-
this.componentMap[componentName].htmlAttributes.class !== "" &&
226-
this.componentMap[componentName].htmlAttributes.id !== ""
230+
store.componentMap[componentName].htmlAttributes.class !== "" &&
231+
store.componentMap[componentName].htmlAttributes.id !== ""
227232
) {
228-
return `<template>\n <div id = "${this.componentMap[componentName].htmlAttributes.id}" class = "${this.componentMap[componentName].htmlAttributes.class}">\n${templateTagStr} </div>\n</template>`;
233+
return `<template>\n <div id = "${store.componentMap[componentName].htmlAttributes.id}" class = "${store.componentMap[componentName].htmlAttributes.class}">\n${templateTagStr} </div>\n</template>`;
229234
} else if (
230-
this.componentMap[componentName].htmlAttributes.class !== "" &&
231-
this.componentMap[componentName].htmlAttributes.id === ""
235+
store.componentMap[componentName].htmlAttributes.class !== "" &&
236+
store.componentMap[componentName].htmlAttributes.id === ""
232237
) {
233-
return `<template>\n <div class = "${this.componentMap[componentName].htmlAttributes.class}">\n${templateTagStr} </div>\n</template>`;
238+
return `<template>\n <div class = "${store.componentMap[componentName].htmlAttributes.class}">\n${templateTagStr} </div>\n</template>`;
234239
} else if (
235-
this.componentMap[componentName].htmlAttributes.class === "" &&
236-
this.componentMap[componentName].htmlAttributes.id !== ""
240+
store.componentMap[componentName].htmlAttributes.class === "" &&
241+
store.componentMap[componentName].htmlAttributes.id !== ""
237242
)
238-
return `<template>\n <div id = "${this.componentMap[componentName].htmlAttributes.id}">\n${templateTagStr} </div>\n</template>`;
239-
else return `<template>\n <div>\n${templateTagStr} </div>\n</template>`;
243+
return `<template>\n <div id = "${store.componentMap[componentName].htmlAttributes.id}">\n${templateTagStr} </div>\n</template>`;
244+
else return `<template>\n <div>\n${templateTagStr} </div>\n</template>`;
240245
};
241246

242247
/**
243248
* @description imports child components into <script>
244249
*/
245250
const writeScript = (componentName, children) => {
246251
// add import mapstate and mapactions if they exist
247-
const currentComponent = this.componentMap[componentName];
252+
const currentComponent = store.componentMap[componentName];
248253
let imports = "";
249254
if (currentComponent.actions.length || currentComponent.state.length) {
250255
imports += "import { ";
@@ -255,7 +260,7 @@ export function useExportComponent() {
255260
imports += ' } from "vuex"\n';
256261
}
257262
// if Typescript toggle is on, import defineComponent
258-
if (this.exportAsTypescript === "on") {
263+
if (store.exportAsTypescript === "on") {
259264
imports += 'import { defineComponent } from "vue";\n';
260265
}
261266
// add imports for children
@@ -277,7 +282,7 @@ export function useExportComponent() {
277282
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`;
278283
});
279284
}
280-
this.routes.HomeView.forEach((element) => {
285+
store.routes.HomeView.forEach((element) => {
281286
element.htmlList.forEach((html) => {
282287
if (html.binding !== "") {
283288
data += `\n ${html.binding}: "PLACEHOLDER FOR VALUE",`;
@@ -313,7 +318,7 @@ export function useExportComponent() {
313318
// concat all code within script tags
314319
// if exportAsTypescript is on, out should be <script lang="ts">
315320
let output;
316-
if (this.exportAsTypescript === "on") {
321+
if (store.exportAsTypescript === "on") {
317322
output = "\n\n<script lang='ts'>\n";
318323
output +=
319324
imports +
@@ -330,7 +335,7 @@ export function useExportComponent() {
330335
output += computed;
331336
output += methods;
332337
// eslint-disable-next-line no-useless-escape
333-
if (this.exportAsTypescript === "on") {
338+
if (store.exportAsTypescript === "on") {
334339
output += "});\n</script>";
335340
} else {
336341
output += "};\n</script>";
@@ -343,10 +348,10 @@ export function useExportComponent() {
343348
* if component is 'App', writes css, else returns <style scoped>
344349
*/
345350
const writeStyle = (componentName) => {
346-
let htmlArray = this.componentMap[componentName].htmlList;
351+
let htmlArray = store.componentMap[componentName].htmlList;
347352
let styleString = "";
348353

349-
this.routes.HomeView.forEach((element) => {
354+
store.routes.HomeView.forEach((element) => {
350355
if (element.htmlAttributes.class !== "") {
351356
styleString += `.${element.htmlAttributes.class} {\nbackground-color: ${element.color};
352357
width: ${element.w}px;
@@ -378,10 +383,11 @@ z-index: ${html.z};
378383
// main logic below for creating single component
379384
// eslint-disable-next-line no-unused-vars
380385
createComponentCode(
381-
path.join(data, this.activeComponent),
382-
this.activeComponent,
383-
this.componentMap[this.activeComponent].children
386+
path.join(data, store.activeComponent),
387+
store.activeComponent,
388+
store.componentMap[store.activeComponent].children
384389
);
385390
};
391+
386392
exportComponent();
387393
}

src/components/left-sidebar/ComponentTab/ParentMultiselect.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const activeComponent = computed(() => store.activeComponent);
3838
const routes = computed(() => store.routes);
3939
const activeRoute = computed(() => store.activeRoute);
4040
41-
const options = computed(() =>
42-
routes.value[activeRoute.value].map((component) => component.componentName)
41+
const options = routes.value[activeRoute.value].map(
42+
(component) => component.componentName
4343
);
4444
4545
const parentSelect: typeof store.parentSelect = (payload) =>

0 commit comments

Comments
 (0)