Skip to content

Commit cbba2e2

Browse files
committed
updated export functionality to include vuex parts
co-authored by: Terry Tilley [email protected]
1 parent 38df0bf commit cbba2e2

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default {
5757
return result
5858
},
5959
// Creates beginner boilerplate
60-
createTemplate (componentName, children) {
60+
createTemplate (componentName) {
6161
// not sure why output was set up like this, was imputted into return statement
6262
// using string literal
6363
// let output = ``

src/components/file_system_interface/ExportProject.vue

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,87 @@ export default {
223223
* @description imports child components into <script>
224224
*/
225225
writeScript (componentName, children) {
226-
let str = ''
226+
// let str = ''
227+
// children.forEach(name => {
228+
// str += `import ${name} from '@/components/${name}.vue';\n`
229+
// })
230+
// let childrenComponentNames = ''
231+
// children.forEach(name => {
232+
// childrenComponentNames += `\t\t${name},\n`
233+
// })
234+
// return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}'
235+
// ,\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
236+
// },
237+
// add import mapstate and mapactions if they exist
238+
let imports = ''
239+
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
240+
imports += 'import { '
241+
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
242+
imports += 'mapState, mapActions'
243+
}
244+
else if (this.activeComponentObj.state.length) imports += 'mapState'
245+
else imports += 'mapActions'
246+
imports += ' } from "vuex"\n'
247+
}
248+
249+
// add imports for children
227250
children.forEach(name => {
228-
str += `import ${name} from '@/components/${name}.vue';\n`
251+
imports += `import ${name} from '@/components/${name}.vue';\n`
229252
})
253+
254+
// add components section
230255
let childrenComponentNames = ''
231256
children.forEach(name => {
232-
childrenComponentNames += `\t\t${name},\n`
257+
childrenComponentNames += ` ${name},\n`
233258
})
234-
return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}',\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
235-
},
236259
260+
// if true add data section and populate with props
261+
let data = ''
262+
if (this.activeComponentObj.props.length){
263+
data += ' data () {\n return {'
264+
this.activeComponentObj.props.forEach(prop => {
265+
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
266+
})
267+
data += '\n'
268+
data += ' }\n'
269+
data += ' },\n'
270+
}
271+
272+
// if true add computed section and populate with state
273+
let computed = ''
274+
if (this.activeComponentObj.state.length){
275+
computed += ' computed: {'
276+
computed += '\n ...mapState(['
277+
this.activeComponentObj.state.forEach((state) =>{
278+
computed += `\n "${state}",`
279+
})
280+
computed += '\n ]),\n'
281+
computed += ' },\n'
282+
}
283+
284+
// if true add methods section and populate with actions
285+
let methods = ''
286+
if (this.activeComponentObj.actions.length){
287+
methods += ' methods: {'
288+
methods += '\n ...mapActions(['
289+
this.activeComponentObj.actions.forEach((action) => {
290+
methods += `\n "${action}",`
291+
})
292+
methods += '\n ]),\n'
293+
methods += ' },\n'
294+
}
295+
296+
// concat all code within script tags
297+
let output = '\n\n<script>\n'
298+
output += imports + '\nexport default {\n name: ' + componentName
299+
output += ',\n components: {\n'
300+
output += childrenComponentNames + ' },\n'
301+
output += data
302+
output += computed
303+
output += methods
304+
output += '};\n<\/script>'
305+
return output
306+
},
237307
/**
238308
* @description writes the <style> in vue component
239309
* if component is 'App', writes css, else returns <style scoped>
@@ -402,7 +472,7 @@ export default {
402472
}
403473
},
404474
computed: {
405-
...mapState(['componentMap', 'imagePath'])
475+
...mapState(['componentMap', 'imagePath', 'activeComponentObj'])
406476
}
407477
}
408478

0 commit comments

Comments
 (0)