Add: show timelines with some format

This commit is contained in:
Cutls 2019-04-24 23:48:26 +09:00
parent a9c3d4567d
commit ba5350bf59

View File

@ -14,7 +14,38 @@
<div id="timelines"> <div id="timelines">
<div v-for="(value, key, index) in pubTL" :key="index" class="tl"> <div v-for="(value, key, index) in pubTL" :key="index" class="tl">
{{value.name}} {{value.name}}
<div v-for="[id,status] in sortedStatus(value.statuses)" :key="id" class="tl">{{status.id}}</div> <!--とりあえずここに書かせて-->
<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>
</div> </div>
</div> </div>
<BaseButton <BaseButton
@ -27,91 +58,112 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ipcRenderer } from 'electron' import { ipcRenderer } from "electron";
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from "vue-property-decorator";
import { Status } from 'megalodon' import { Status } from "megalodon";
import '@/extensions/map-sortbyvalue' // Add sortByValue function to Map prototype import "@/extensions/map-sortbyvalue"; // Add sortByValue function to Map prototype
type DeleteListener = (e: Event, id: number) => void type DeleteListener = (e: Event, id: number) => void;
type Instance = string type Instance = string;
type Timeline = { type Timeline = {
name: string name: string;
statuses?: Map<number, Status> statuses?: Map<number, Status>;
} };
type Timelines = Timeline[] type Timelines = Timeline[];
type UpdateListener = (e: Event, status: Status) => void type UpdateListener = (e: Event, status: Status) => void;
@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 deleteListeners: [string, DeleteListener][] = [];
public pubTL: Timelines = [] public pubTL: Timelines = [];
//test
public pref = {
static: false
};
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]) => { this.deleteListeners.forEach(([name, listener]) => {
ipcRenderer.removeListener(name, listener) ipcRenderer.removeListener(name, listener);
}) });
} }
public get hasDomain() { public get hasDomain() {
return this.instance != '' return this.instance != "";
} }
public sortedStatus(statuses: Map<number, Status>): Map<number, Status> { public sortedStatus(statuses: Map<number, Status>): Map<number, Status> {
return statuses.sortByValue((s1, s2): number => { return statuses.sortByValue(
return s1.created_at > s2.created_at ? -1 : 1 (s1, s2): number => {
}) return s1.created_at > s2.created_at ? -1 : 1;
}
);
} }
public addTL() { public addTL() {
let timeline: Timeline = { name: this.instance } let timeline: Timeline = { name: this.instance };
this.showInput = false this.showInput = false;
this.instance = '' this.instance = "";
this.pubTL.push(timeline) this.pubTL.push(timeline);
// TL // TL
this.loadTL(timeline) this.loadTL(timeline);
// streaming // streaming
this.subscribeStreaming(timeline) this.subscribeStreaming(timeline);
} }
public loadTL(timeline: Timeline) { public loadTL(timeline: Timeline) {
let statuses: Status[] = ipcRenderer.sendSync('no-auth-timeline', timeline.name) let statuses: Status[] = ipcRenderer.sendSync(
timeline.statuses = new Map(statuses.map((status): [number, Status] => [status.id, status])) "no-auth-timeline",
timeline.name
);
timeline.statuses = new Map(
statuses.map((status): [number, Status] => [status.id, status])
);
} }
public async subscribeStreaming(timeline: Timeline) { public async subscribeStreaming(timeline: Timeline) {
// update // update
let updateListener = (_: Event, status: Status) => { let updateListener = (_: Event, status: Status) => {
if (timeline.statuses === undefined) { if (timeline.statuses === undefined) {
timeline.statuses = new Map() timeline.statuses = new Map();
} }
timeline.statuses.set(status.id, status) timeline.statuses.set(status.id, status);
this.$forceUpdate() this.$forceUpdate();
} };
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
]);
// delete // delete
let deleteListener = (_: Event, id: number) => { let deleteListener = (_: Event, id: number) => {
if (timeline.statuses === undefined) { if (timeline.statuses === undefined) {
timeline.statuses = new Map() timeline.statuses = new Map();
} }
timeline.statuses.delete(id) timeline.statuses.delete(id);
this.$forceUpdate() this.$forceUpdate();
} };
ipcRenderer.on(`delete-${timeline.name}-no-auth`, deleteListener) ipcRenderer.on(`delete-${timeline.name}-no-auth`, deleteListener);
this.deleteListeners.push([`delete-${timeline.name}-no-auth`, deleteListener]) this.deleteListeners.push([
`delete-${timeline.name}-no-auth`,
deleteListener
]);
ipcRenderer.send('open-streaming', timeline.name, 'no-auth') ipcRenderer.send("open-streaming", timeline.name, "no-auth");
}
public showAccount(id: number) {
console.log("Account dialog:" + id);
} }
} }
</script>= </script>=
@ -143,4 +195,31 @@ input {
height: 100%; height: 100%;
flex-grow: 4; flex-grow: 4;
} }
.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;
img{
width:100%;
}
}
.tootUser {
grid-area: user;
}
.tootContent {
grid-area: content;
}
.tootMedia {
grid-area: media;
}
.tootCard {
grid-area: card;
}
.tootAction {
grid-area: card;
}
}
</style> </style>