thedesk/src/components/AddColumn/PublicTimeline.vue

206 lines
5.6 KiB
Vue
Raw Normal View History

<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
<!--とりあえずここに書かせて-->
<div v-for="[id,status] in sortedStatus(value.statuses)" :key="id" class="tl">
<div class="toot">
<div class="tootAvatar">
<!--ここは公開TLなので@clickでユーザー情報表示はない-->
<img :src="pref.static ? status.account.avatar : status.account.avatar_static">
</div>
<div class="tootUser">
{{status.account.display_name}}
<small>@{{status.account.acct}}</small>
</div>
<div class="tootContent" v-html="status.content"></div>
<div class="tootMedia" v-if="status.media_attachments">
<div
v-for="(media,mediaId) in status.media_attachments"
:key="mediaId"
class="tootImg"
>
<img :src="media.preview_url" @click="showImage(media.url, media.type)">
</div>
</div>
<div class="tootCard" v-if="status.card">
<template
v-if="status.card.description"
>{{status.card.title}} - {{status.card.description}}</template>
<template v-else-if="status.card.html" v-html="status.card.html"></template>
</div>
<div class="tootAction">
<!--ここは公開TLなのでふぁぼ等はなし-->
</div>
</div>
</div>
2019-04-23 23:42:07 +09:00
</div>
</div>
<BaseButton
v-if="!showInput"
@click.native="showInput = true"
class="primary fill"
style="--font-size:.8em;"
>Show Menu</BaseButton>
</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-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
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
@Component
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 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
}
public get hasDomain() {
2019-04-25 00:52:40 +09:00
return this.instance != ""
}
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() {
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を取得
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
}
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
)
// 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
}
}
</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-24 23:48:26 +09:00
.toot {
text-align: left;
display: grid;
grid-template-columns: 43px 2fr 1fr;
grid-template-areas: "avatar user user" "avatar content content" "avatar media media" "avatar card card" "avatar action action";
.tootAvatar {
grid-area: avatar;
2019-04-25 00:52:40 +09:00
img {
width: 100%;
2019-04-24 23:48:26 +09:00
}
}
.tootUser {
grid-area: user;
}
.tootContent {
grid-area: content;
}
.tootMedia {
grid-area: media;
}
.tootCard {
grid-area: card;
}
.tootAction {
grid-area: card;
}
}
</style>