2019-04-23 04:46:17 +09:00
|
|
|
<template>
|
|
|
|
<div>
|
2019-04-23 23:42:07 +09:00
|
|
|
<div v-if="showInput">
|
2019-04-24 17:04:44 +09:00
|
|
|
<form @submit.prevent="addTL">
|
2019-04-25 14:06:36 +09:00
|
|
|
<BaseInputText placeholder="e.g:mstdn.jp" v-model="instance"/>
|
2019-04-24 17:04:44 +09:00
|
|
|
<BaseButton
|
|
|
|
type="submit"
|
|
|
|
class="primary fill"
|
|
|
|
style="--font-size:.8em;"
|
|
|
|
:disabled="!hasDomain"
|
|
|
|
>Add Column</BaseButton>
|
|
|
|
</form>
|
2019-04-23 23:42:07 +09:00
|
|
|
</div>
|
|
|
|
<div id="timelines">
|
|
|
|
<div v-for="(value, key, index) in pubTL" :key="index" class="tl">
|
2019-04-24 06:07:15 +09:00
|
|
|
{{value.name}}
|
2019-04-24 23:48:26 +09:00
|
|
|
<!--とりあえずここに書かせて-->
|
2019-04-25 21:53:51 +09:00
|
|
|
<TimelineToot
|
|
|
|
v-for="[id,status] in sortedStatus(value.statuses)"
|
|
|
|
:key="id"
|
|
|
|
:status="status"
|
|
|
|
:pref-static="pref.static"
|
|
|
|
/>
|
2019-04-23 23:42:07 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-23 04:46:17 +09:00
|
|
|
<BaseButton
|
2019-04-24 03:40:04 +09:00
|
|
|
v-if="!showInput"
|
|
|
|
@click.native="showInput = true"
|
|
|
|
class="primary fill"
|
|
|
|
style="--font-size:.8em;"
|
|
|
|
>Show Menu</BaseButton>
|
2019-04-23 04:46:17 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-04-25 00:52:40 +09:00
|
|
|
import { ipcRenderer } from "electron"
|
|
|
|
import { Component, Vue } from "vue-property-decorator"
|
|
|
|
import { Status } from "megalodon"
|
2019-04-23 04:46:17 +09:00
|
|
|
|
2019-04-25 21:53:51 +09:00
|
|
|
import TimelineToot from '@/components/Timeline/Toot.vue'
|
|
|
|
|
2019-04-25 00:52:40 +09:00
|
|
|
import "@/extensions/map-sortbyvalue" // Add sortByValue function to Map prototype
|
2019-04-24 19:47:26 +09:00
|
|
|
|
2019-04-25 00:52:40 +09:00
|
|
|
type DeleteListener = (e: Event, id: number) => void
|
|
|
|
type Instance = string
|
2019-04-24 06:07:15 +09:00
|
|
|
type Timeline = {
|
2019-04-25 00:52:40 +09:00
|
|
|
name: string
|
2019-04-25 14:21:21 +09:00
|
|
|
statuses: Map<number, Status>
|
|
|
|
error?: Error
|
2019-04-25 00:52:40 +09:00
|
|
|
}
|
|
|
|
type Timelines = Timeline[]
|
|
|
|
type UpdateListener = (e: Event, status: Status) => void
|
2019-04-24 19:31:06 +09:00
|
|
|
|
2019-04-25 21:53:51 +09:00
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
TimelineToot
|
|
|
|
}
|
|
|
|
})
|
2019-04-23 04:46:17 +09:00
|
|
|
export default class AddColumn extends Vue {
|
2019-04-25 00:52:40 +09:00
|
|
|
public instance: Instance = ""
|
|
|
|
public showInput: boolean = true
|
|
|
|
public updateListeners: [string, UpdateListener][] = []
|
|
|
|
public deleteListeners: [string, DeleteListener][] = []
|
|
|
|
public pubTL: Timelines = []
|
2019-04-24 23:48:26 +09:00
|
|
|
//test
|
|
|
|
public pref = {
|
|
|
|
static: false
|
2019-04-25 00:52:40 +09:00
|
|
|
}
|
2019-04-24 03:40:04 +09:00
|
|
|
|
2019-04-24 17:15:42 +09:00
|
|
|
beforeDestroy() {
|
|
|
|
this.updateListeners.forEach(([name, listener]) => {
|
2019-04-25 00:52:40 +09:00
|
|
|
ipcRenderer.removeListener(name, listener)
|
|
|
|
})
|
2019-04-24 17:42:35 +09:00
|
|
|
this.deleteListeners.forEach(([name, listener]) => {
|
2019-04-25 00:52:40 +09:00
|
|
|
ipcRenderer.removeListener(name, listener)
|
|
|
|
})
|
2019-04-24 17:15:42 +09:00
|
|
|
}
|
|
|
|
|
2019-04-24 03:40:04 +09:00
|
|
|
public get hasDomain() {
|
2019-04-25 00:52:40 +09:00
|
|
|
return this.instance != ""
|
2019-04-24 03:40:04 +09:00
|
|
|
}
|
2019-04-23 23:42:07 +09:00
|
|
|
|
2019-04-24 19:47:26 +09:00
|
|
|
public sortedStatus(statuses: Map<number, Status>): Map<number, Status> {
|
2019-04-24 23:48:26 +09:00
|
|
|
return statuses.sortByValue(
|
|
|
|
(s1, s2): number => {
|
2019-04-25 00:52:40 +09:00
|
|
|
return s1.created_at > s2.created_at ? -1 : 1
|
2019-04-24 23:48:26 +09:00
|
|
|
}
|
2019-04-25 00:52:40 +09:00
|
|
|
)
|
2019-04-24 19:47:26 +09:00
|
|
|
}
|
|
|
|
|
2019-04-23 23:42:07 +09:00
|
|
|
public addTL() {
|
2019-04-25 14:21:21 +09:00
|
|
|
let timeline: Timeline = { name: this.instance, statuses: new Map() }
|
2019-04-24 17:31:18 +09:00
|
|
|
|
2019-04-25 00:52:40 +09:00
|
|
|
this.showInput = false
|
|
|
|
this.instance = ""
|
2019-04-24 17:42:35 +09:00
|
|
|
|
2019-04-25 00:52:40 +09:00
|
|
|
this.pubTL.push(timeline)
|
2019-04-24 19:31:06 +09:00
|
|
|
// 最新のTLを取得
|
2019-04-25 14:21:21 +09:00
|
|
|
ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (e: Event, statuses: Status[], error?: Error) => {
|
|
|
|
timeline.error = error
|
|
|
|
if (error === undefined) {
|
|
|
|
this.loadTL(timeline, statuses)
|
|
|
|
}
|
|
|
|
this.$forceUpdate()
|
|
|
|
})
|
|
|
|
ipcRenderer.send("no-auth-timeline", timeline.name)
|
2019-04-24 19:31:06 +09:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:21:21 +09:00
|
|
|
|
|
|
|
public loadTL(timeline: Timeline, statuses: Status[]) {
|
2019-04-24 23:48:26 +09:00
|
|
|
timeline.statuses = new Map(
|
|
|
|
statuses.map((status): [number, Status] => [status.id, status])
|
2019-04-25 00:52:40 +09:00
|
|
|
)
|
2019-04-25 14:21:21 +09:00
|
|
|
|
|
|
|
// streamingを開始
|
|
|
|
this.subscribeStreaming(timeline)
|
2019-04-24 19:31:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public async subscribeStreaming(timeline: Timeline) {
|
|
|
|
// updateイベントを購読
|
2019-04-24 17:15:42 +09:00
|
|
|
let updateListener = (_: Event, status: Status) => {
|
2019-04-25 00:52:40 +09:00
|
|
|
timeline.statuses.set(status.id, status)
|
|
|
|
this.$forceUpdate()
|
|
|
|
}
|
|
|
|
ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener)
|
2019-04-24 23:48:26 +09:00
|
|
|
this.updateListeners.push([
|
|
|
|
`update-${timeline.name}-no-auth`,
|
|
|
|
updateListener
|
2019-04-25 00:52:40 +09:00
|
|
|
])
|
2019-04-24 17:15:42 +09:00
|
|
|
|
2019-04-24 19:31:06 +09:00
|
|
|
// deleteイベントを購読
|
2019-04-24 17:42:35 +09:00
|
|
|
let deleteListener = (_: Event, id: number) => {
|
2019-04-25 00:52:40 +09:00
|
|
|
timeline.statuses.delete(id)
|
|
|
|
this.$forceUpdate()
|
|
|
|
}
|
|
|
|
ipcRenderer.on(`delete-${timeline.name}-no-auth`, deleteListener)
|
2019-04-24 23:48:26 +09:00
|
|
|
this.deleteListeners.push([
|
|
|
|
`delete-${timeline.name}-no-auth`,
|
|
|
|
deleteListener
|
2019-04-25 00:52:40 +09:00
|
|
|
])
|
2019-04-24 23:48:26 +09:00
|
|
|
|
2019-04-25 00:52:40 +09:00
|
|
|
ipcRenderer.send("open-streaming", timeline.name, "no-auth")
|
2019-04-24 23:48:26 +09:00
|
|
|
}
|
2019-04-24 17:42:35 +09:00
|
|
|
|
2019-04-24 23:48:26 +09:00
|
|
|
public showAccount(id: number) {
|
2019-04-25 00:52:40 +09:00
|
|
|
console.log("Account dialog:" + id)
|
2019-04-24 01:07:20 +09:00
|
|
|
}
|
2019-04-23 04:46:17 +09:00
|
|
|
}
|
|
|
|
</script>=
|
|
|
|
|
|
|
|
<style scoped lang="postcss">
|
2019-04-24 03:58:06 +09:00
|
|
|
#timelines {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
2019-04-23 23:42:07 +09:00
|
|
|
}
|
2019-04-24 03:58:06 +09:00
|
|
|
.tl {
|
|
|
|
height: 100%;
|
2019-04-23 23:42:07 +09:00
|
|
|
flex-grow: 4;
|
|
|
|
}
|
2019-04-23 04:46:17 +09:00
|
|
|
</style>
|