Introduce: Timeline

This commit is contained in:
Cutls 2019-04-27 15:08:25 +09:00
parent 488f4d078e
commit 8118826df5
4 changed files with 68 additions and 61 deletions

View File

@ -14,7 +14,6 @@
<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}}
<!--とりあえずここに書かせて-->
<TimelineToot <TimelineToot
v-for="[id,status] in value.statuses" v-for="[id,status] in value.statuses"
:key="id" :key="id"

View File

@ -44,7 +44,7 @@ export default class Auth extends Vue {
ipcRenderer.once( ipcRenderer.once(
`login-complete`, `login-complete`,
(e: Event) => { (e: Event) => {
status="timeline"
} }
); );
} }

View File

@ -13,12 +13,11 @@
</div> </div>
<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}}
<!--とりあえずここに書かせて-->
<TimelineToot <TimelineToot
v-for="[id,status] in value.statuses" v-for="[id,account,status] in value.statuses"
:key="id" :key="id"
:status="status" :status="status"
:account="account"
:pref-static="pref.static" :pref-static="pref.static"
/> />
</div> </div>
@ -33,23 +32,24 @@
</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 TimelineToot from '@/components/Timeline/Toot.vue' import TimelineToot from "@/components/Timeline/Toot.vue";
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 type: string;
statuses: Map<number, Status> account: string;
error?: Error statuses: Map<number, Status>;
} error?: Error;
type Timelines = Timeline[] };
type UpdateListener = (e: Event, status: Status) => void type Timelines = Timeline[];
type UpdateListener = (e: Event, status: Status) => void;
@Component({ @Component({
components: { components: {
@ -57,94 +57,102 @@ type UpdateListener = (e: Event, status: Status) => void
} }
}) })
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 type: string = "";
public deleteListeners: [string, DeleteListener][] = [] public account: string = "";
public pubTL: Timelines = [] public updateListeners: [string, UpdateListener][] = [];
public deleteListeners: [string, DeleteListener][] = [];
public TL: Timelines = [];
//test //test
public pref = { public pref = {
static: false 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( return statuses.sortByValue(
(s1, s2): number => { (s1, s2): number => {
return s1.created_at > s2.created_at ? -1 : 1 return s1.created_at > s2.created_at ? -1 : 1;
} }
) );
} }
public addTL() { public addTL() {
let timeline: Timeline = { name: this.instance, statuses: new Map() } let timeline: Timeline = {
type: this.type,
account: this.account,
statuses: new Map()
};
this.showInput = false this.showInput = false;
this.instance = "" this.type = "";
this.account = "";
this.pubTL.push(timeline) this.TL.push(timeline);
// TL // TL
ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (e: Event, statuses: Status[], error?: Error) => { ipcRenderer.once(
timeline.error = error `timeline-${timeline.name}-no-auth`,
(e: Event, statuses: Status[], error?: Error) => {
timeline.error = error;
if (error === undefined) { if (error === undefined) {
this.loadTL(timeline, statuses) this.loadTL(timeline, statuses);
} }
this.$forceUpdate() this.$forceUpdate();
}) }
ipcRenderer.send("no-auth-timeline", timeline.name) );
ipcRenderer.send("no-auth-timeline", timeline.name);
} }
public loadTL(timeline: Timeline, statuses: Status[]) { public loadTL(timeline: Timeline, statuses: Status[]) {
timeline.statuses = new Map( timeline.statuses = new Map(
statuses.map((status): [number, Status] => [status.id, status]) statuses.map((status): [number, Status] => [status.id, status])
) );
// streaming // streaming
this.subscribeStreaming(timeline) this.subscribeStreaming(timeline);
} }
public async subscribeStreaming(timeline: Timeline) { public async subscribeStreaming(timeline: Timeline) {
// update // update
let updateListener = (_: Event, status: Status) => { let updateListener = (_: Event, status: Status) => {
timeline.statuses.set(status.id, status) timeline.statuses.set(status.id, status);
timeline.statuses = this.sortedStatus(timeline.statuses) timeline.statuses = this.sortedStatus(timeline.statuses);
this.$forceUpdate() this.$forceUpdate();
} };
ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener) ipcRenderer.on(`update-${timeline.name}-no-auth`, updateListener);
this.updateListeners.push([ this.updateListeners.push([
`update-${timeline.name}-no-auth`, `update-${timeline.name}-no-auth`,
updateListener updateListener
]) ]);
// delete // delete
let deleteListener = (_: Event, id: number) => { let deleteListener = (_: Event, id: number) => {
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([ this.deleteListeners.push([
`delete-${timeline.name}-no-auth`, `delete-${timeline.name}-no-auth`,
deleteListener deleteListener
]) ]);
ipcRenderer.send("open-streaming", timeline.name, "no-auth") ipcRenderer.send("open-streaming", timeline.name, "no-auth");
} }
public showAccount(id: number) { public showAccount(id: number) {
console.log("Account dialog:" + id) console.log("Account dialog:" + id);
} }
} }
</script>= </script>=

View File

@ -9,7 +9,7 @@
<BaseOverlay <BaseOverlay
v-show="status !== 'welcome'" v-show="status !== 'welcome'"
@close="status = 'welcome'" @close="status = 'welcome'"
:title="status === 'login' ? loginButton : publicTLButton" :title="status === 'login' ? loginButton : status === 'timeline' ? TLButton : publicTLButton"
> >
<Login v-if="status === 'login'"/> <Login v-if="status === 'login'"/>
<PublicTimeline v-else-if="status === 'public_timeline'"/> <PublicTimeline v-else-if="status === 'public_timeline'"/>
@ -22,7 +22,7 @@
import { Component, Vue } from 'vue-property-decorator' import { Component, Vue } from 'vue-property-decorator'
import Login from './Preference/AccountManager.vue' import Login from './Preference/AccountManager.vue'
import Timeline from './Timeliine/Timeline.vue' import Timeline from './Timeline/Timeline.vue'
import PublicTimeline from './AddColumn/PublicTimeline.vue' import PublicTimeline from './AddColumn/PublicTimeline.vue'
type Status = 'welcome' | 'login' | 'public_timeline' | 'timeline' type Status = 'welcome' | 'login' | 'public_timeline' | 'timeline'