Add listener for add-timeline to Main component

This commit is contained in:
kPherox 2019-05-22 16:04:19 +09:00
parent 8221f5495f
commit 7359995a3e
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
2 changed files with 14 additions and 2 deletions

View File

@ -9,6 +9,7 @@
</template>
<script lang="ts">
import { ipcRenderer } from 'electron'
import { Component, Prop, Vue } from 'vue-property-decorator'
import Column from '@/components/Timeline/Column.vue'
@ -31,6 +32,7 @@ export default class Main extends Vue {
beforeDestroy() {
// this.timelines LocalStorage
ipcRenderer.removeAllListeners('add-timeline')
}
created() {
@ -41,6 +43,16 @@ export default class Main extends Vue {
this.timelines.push(this.initTimeline._id)
}
mounted() {
ipcRenderer.on('add-timeline', (_e: Event, tl?: TimelineDoc, error?: Error) => {
if (error != undefined || tl === undefined) {
console.error(error)
return
}
this.timelines.push(tl._id)
})
}
}
</script>

View File

@ -54,8 +54,8 @@ export default class Timeline {
let newDoc = await db.insert(docs)
event.sender.send(`add-timeline`, newDoc)
} catch (err) {
let error = new Error("You cannot login already logined account.")
error.name = "ERROR_YOU_TRY_ANOTHER_ACCOUNT"
let error = new Error("Cannot save timeline.")
error.name = "ERROR_ADD_TIMELINE"
event.sender.send(`add-timeline`, undefined, error)
}
}