Change renderer add-timeline value to nedb id

This commit is contained in:
kPherox 2019-05-22 16:42:03 +09:00
parent c0b89e99b0
commit 28fb6ffda6
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
3 changed files with 12 additions and 24 deletions

View File

@ -14,19 +14,13 @@ import { Component, Prop, Vue } from 'vue-property-decorator'
import Column from '@/components/Timeline/Column.vue' import Column from '@/components/Timeline/Column.vue'
interface TimelineDoc {
_id: string
name: string
type: string
}
@Component({ @Component({
components: { components: {
Column, Column,
} }
}) })
export default class Main extends Vue { export default class Main extends Vue {
@Prop() public initTimeline?: TimelineDoc @Prop() public initTimelineId?: string
public timelines: string[] = [] public timelines: string[] = []
@ -36,21 +30,21 @@ export default class Main extends Vue {
} }
created() { created() {
if (this.initTimeline === undefined) { if (this.initTimelineId === undefined) {
// LocalStorage this.timelines // LocalStorage this.timelines
return return
} }
this.timelines.push(this.initTimeline._id) this.timelines.push(this.initTimelineId)
} }
mounted() { mounted() {
ipcRenderer.on('add-timeline', (_e: Event, tl?: TimelineDoc, error?: Error) => { ipcRenderer.on('add-timeline', (_e: Event, id?: string, error?: Error) => {
if (error != undefined || tl === undefined) { if (error != undefined || id === undefined) {
console.error(error) console.error(error)
return return
} }
this.timelines.push(tl._id) this.timelines.push(id)
}) })
} }
} }

View File

@ -58,7 +58,7 @@ export default class Timeline {
try { try {
let newDoc = await db.insert(docs) let newDoc = await db.insert(docs)
event.sender.send(`add-timeline`, newDoc) event.sender.send(`add-timeline`, newDoc._id)
} catch (err) { } catch (err) {
let error = new Error("Cannot save timeline.") let error = new Error("Cannot save timeline.")
error.name = "ERROR_ADD_TIMELINE" error.name = "ERROR_ADD_TIMELINE"

View File

@ -1,7 +1,7 @@
<template> <template>
<div id="app" :style="styles"> <div id="app" :style="styles">
<Welcome v-if="isStartup"/> <Welcome v-if="isStartup"/>
<Main :init-timeline="initTimeline" v-else/> <Main :init-timeline-id="initTimelineId" v-else/>
</div> </div>
</template> </template>
@ -12,12 +12,6 @@ import { Component, Vue } from 'vue-property-decorator'
import Main from '@/components/Main.vue' import Main from '@/components/Main.vue'
import Welcome from '@/components/Welcome.vue' import Welcome from '@/components/Welcome.vue'
interface TimelineDoc {
_id: string
name: string
type: string
}
@Component({ @Component({
components: { components: {
Main, Main,
@ -28,7 +22,7 @@ export default class App extends Vue {
public isDarkMode: boolean = false public isDarkMode: boolean = false
public isStartup: boolean = true public isStartup: boolean = true
public fontSize: string = '16px' public fontSize: string = '16px'
public initTimeline?: TimelineDoc public initTimelineId?: string
public get styles(): { [key: string]: string } { public get styles(): { [key: string]: string } {
return { return {
@ -49,12 +43,12 @@ export default class App extends Vue {
ipcRenderer.on('change-color-theme', () => this.isDarkMode = ipcRenderer.sendSync('dark-theme')) ipcRenderer.on('change-color-theme', () => this.isDarkMode = ipcRenderer.sendSync('dark-theme'))
// TODO: TL // TODO: TL
if (this.isStartup) { if (this.isStartup) {
ipcRenderer.once('add-timeline', (_e: Event, tl?: TimelineDoc, error?: Error) => { ipcRenderer.once('add-timeline', (_e: Event, id?: string, error?: Error) => {
if (error != undefined || tl === undefined) { if (error != undefined) {
console.error(error) console.error(error)
return return
} }
this.initTimeline = tl this.initTimelineId = id
this.isStartup = false this.isStartup = false
}) })
} }