Add delete listener

This commit is contained in:
kPherox 2019-04-24 17:42:35 +09:00
parent 0dde80f267
commit 5e4fa1726d
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D

View File

@ -37,18 +37,23 @@ type Timeline = {
statuses: Map<number, Status> statuses: Map<number, Status>
} }
type UpdateListener = (e: Event, status: Status) => void type UpdateListener = (e: Event, status: Status) => void
type DeleteListener = (e: Event, id: number) => void
type Timelines = Timeline[] type Timelines = Timeline[]
@Component @Component
export default class AddColumn extends Vue { export default class AddColumn extends Vue {
public instance: Instance = '' public instance: Instance = ''
public showInput: boolean = true public showInput: boolean = true
public updateListeners: [string, UpdateListener][] = [] public updateListeners: [string, UpdateListener][] = []
public deleteListeners: [string, DeleteListener][] = []
public pubTL: Timelines = [] public pubTL: Timelines = []
beforeDestroy() { beforeDestroy() {
this.updateListeners.forEach(([name, listener]) => { this.updateListeners.forEach(([name, listener]) => {
ipcRenderer.removeListener(name, listener) ipcRenderer.removeListener(name, listener)
}) })
this.deleteListeners.forEach(([name, listener]) => {
ipcRenderer.removeListener(name, listener)
})
} }
public get hasDomain() { public get hasDomain() {
@ -56,11 +61,11 @@ export default class AddColumn extends Vue {
} }
public addTL() { public addTL() {
this.showInput = false
let instance = this.instance
let timeline: Timeline = { name: this.instance, statuses: new Map() } let timeline: Timeline = { name: this.instance, statuses: new Map() }
this.showInput = false
this.instance = ''
this.pubTL.push(timeline) this.pubTL.push(timeline)
this.loadTL(timeline) this.loadTL(timeline)
@ -71,7 +76,14 @@ export default class AddColumn extends Vue {
ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener) ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener)
this.updateListeners.push([`update-${timeline.name}-no-auth`, updateListener]) this.updateListeners.push([`update-${timeline.name}-no-auth`, updateListener])
ipcRenderer.send('open-streaming', instance, 'no-auth') let deleteListener = (_: Event, id: number) => {
timeline.statuses.delete(id)
this.$forceUpdate()
}
ipcRenderer.on(`delete-${timeline.name}-no-auth`, deleteListener)
this.deleteListeners.push([`delete-${timeline.name}-no-auth`, deleteListener])
ipcRenderer.send('open-streaming', timeline.name, 'no-auth')
} }
public loadTL(timeline: Timeline) { public loadTL(timeline: Timeline) {