Skip to content

Commit b16cc07

Browse files
committed
fixed error when canceling save project
1 parent 10553fd commit b16cc07

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/components/SaveProjectComponent.vue

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
// returns location of where file is stored
3737
parseFileName (file) {
3838
// 'asdf/asdff/sdf.txt -> sdf.txt
39-
return file.split('/').pop()
39+
if (file) return file.split('/').pop()
4040
},
4141
// deletes anything attached to html element
4242
parseAndDelete (htmlList) {
@@ -75,37 +75,39 @@ export default {
7575
})
7676
7777
let fileName = this.parseFileName(data)
78-
79-
this.$set(this.$store.state.projects, this.$store.state.activeTab, {
80-
filename: fileName,
81-
lastSavedLocation: data
82-
})
83-
let state = this.$store.state
84-
let routes = state.routes
85-
// for each route call parseAndDelete on htmlList
86-
for (let view in routes) {
87-
// console.log('views in Routes', routes[view])
88-
routes[view].forEach(component => {
89-
let htmlList = component.htmlList
90-
this.parseAndDelete(htmlList)
78+
// if valid fileName
79+
if (fileName) {
80+
this.$set(this.$store.state.projects, this.$store.state.activeTab, {
81+
filename: fileName,
82+
lastSavedLocation: data
9183
})
92-
}
93-
let componentMap = this.$store.state.componentMap
94-
for (let component in componentMap) {
95-
if (component.htmlList) {
96-
let comphtml = component.htmlList
97-
this.parseAndDelete(comphtml)
84+
let state = this.$store.state
85+
let routes = state.routes
86+
// for each route call parseAndDelete on htmlList
87+
for (let view in routes) {
88+
// console.log('views in Routes', routes[view])
89+
routes[view].forEach(component => {
90+
let htmlList = component.htmlList
91+
this.parseAndDelete(htmlList)
92+
})
9893
}
94+
let componentMap = this.$store.state.componentMap
95+
for (let component in componentMap) {
96+
if (component.htmlList) {
97+
let comphtml = component.htmlList
98+
this.parseAndDelete(comphtml)
99+
}
100+
}
101+
102+
fs.writeFileSync(data, JSON.stringify(state))
103+
localforage
104+
.setItem(fileName, JSON.parse(fs.readFileSync(data, 'utf8')))
105+
// .then(result => {
106+
// console.log('saved ', fileName, 'to local forage')
107+
// console.log('result is', result)
108+
// })
109+
// console.log('PROJECT SAVED AS A JSON OBJECT!')
99110
}
100-
101-
fs.writeFileSync(data, JSON.stringify(state))
102-
localforage
103-
.setItem(fileName, JSON.parse(fs.readFileSync(data, 'utf8')))
104-
// .then(result => {
105-
// console.log('saved ', fileName, 'to local forage')
106-
// console.log('result is', result)
107-
// })
108-
// console.log('PROJECT SAVED AS A JSON OBJECT!')
109111
}
110112
},
111113
// on components creation these key presses will trigger save project

0 commit comments

Comments
 (0)