thedesk/src/components/AddColumn/PublicTimeline.vue

225 lines
5.9 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">
<input type="text" placeholder="e.g:mstdn.jp" v-model="instance">
<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-24 23:48:26 +09:00
import { ipcRenderer } from "electron";
import { Component, Vue } from "vue-property-decorator";
import { Status } from "megalodon";
2019-04-24 23:48:26 +09:00
import "@/extensions/map-sortbyvalue"; // Add sortByValue function to Map prototype
2019-04-24 19:47:26 +09:00
2019-04-24 23:48:26 +09:00
type DeleteListener = (e: Event, id: number) => void;
type Instance = string;
2019-04-24 06:07:15 +09:00
type Timeline = {
2019-04-24 23:48:26 +09:00
name: string;
statuses?: Map<number, Status>;
};
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-24 23:48:26 +09:00
public instance: Instance = "";
public showInput: boolean = true;
public updateListeners: [string, UpdateListener][] = [];
public deleteListeners: [string, DeleteListener][] = [];
public pubTL: Timelines = [];
//test
public pref = {
static: false
};
2019-04-24 17:15:42 +09:00
beforeDestroy() {
this.updateListeners.forEach(([name, listener]) => {
2019-04-24 23:48:26 +09:00
ipcRenderer.removeListener(name, listener);
});
2019-04-24 17:42:35 +09:00
this.deleteListeners.forEach(([name, listener]) => {
2019-04-24 23:48:26 +09:00
ipcRenderer.removeListener(name, listener);
});
2019-04-24 17:15:42 +09:00
}
public get hasDomain() {
2019-04-24 23:48:26 +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 => {
return s1.created_at > s2.created_at ? -1 : 1;
}
);
2019-04-24 19:47:26 +09:00
}
2019-04-23 23:42:07 +09:00
public addTL() {
2019-04-24 23:48:26 +09:00
let timeline: Timeline = { name: this.instance };
2019-04-24 17:31:18 +09:00
2019-04-24 23:48:26 +09:00
this.showInput = false;
this.instance = "";
2019-04-24 17:42:35 +09:00
2019-04-24 23:48:26 +09:00
this.pubTL.push(timeline);
2019-04-24 19:31:06 +09:00
// 最新のTLを取得
2019-04-24 23:48:26 +09:00
this.loadTL(timeline);
2019-04-24 06:15:56 +09:00
2019-04-24 19:31:06 +09:00
// streamingを開始
2019-04-24 23:48:26 +09:00
this.subscribeStreaming(timeline);
2019-04-24 19:31:06 +09:00
}
public loadTL(timeline: Timeline) {
2019-04-24 23:48:26 +09:00
let statuses: Status[] = ipcRenderer.sendSync(
"no-auth-timeline",
timeline.name
);
timeline.statuses = new Map(
statuses.map((status): [number, Status] => [status.id, status])
);
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-24 19:31:06 +09:00
if (timeline.statuses === undefined) {
2019-04-24 23:48:26 +09:00
timeline.statuses = new Map();
2019-04-24 19:31:06 +09:00
}
2019-04-24 23:48:26 +09:00
timeline.statuses.set(status.id, status);
this.$forceUpdate();
};
ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener);
this.updateListeners.push([
`update-${timeline.name}-no-auth`,
updateListener
]);
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-24 19:31:06 +09:00
if (timeline.statuses === undefined) {
2019-04-24 23:48:26 +09:00
timeline.statuses = new Map();
2019-04-24 19:31:06 +09:00
}
2019-04-24 23:48:26 +09:00
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");
}
2019-04-24 17:42:35 +09:00
2019-04-24 23:48:26 +09:00
public showAccount(id: number) {
console.log("Account dialog:" + id);
2019-04-24 01:07:20 +09:00
}
}
</script>=
<style scoped lang="postcss">
input {
color: var(--color);
background-color: transparent;
font-size: var(--font-size);
border: none;
border-bottom: 1px solid #9e9e9e;
border-radius: 0;
line-height: 3em;
width: 80%;
outline: none;
margin: 1em;
transition-duration: 0.5s;
&:focus {
border-color: #26d69a;
}
}
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;
img{
width:100%;
}
}
.tootUser {
grid-area: user;
}
.tootContent {
grid-area: content;
}
.tootMedia {
grid-area: media;
}
.tootCard {
grid-area: card;
}
.tootAction {
grid-area: card;
}
}
</style>