2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Vue, Ref } from "vue-property-decorator";
|
|
|
|
import { ActorType, IActor } from "@/types/actor";
|
|
|
|
import { IFollower } from "@/types/actor/follower.model";
|
2020-07-07 17:19:57 +02:00
|
|
|
import TimeAgo from "javascript-time-ago";
|
2019-12-03 11:29:51 +01:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class RelayMixin extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Ref("table") readonly table!: any;
|
2019-12-03 11:29:51 +01:00
|
|
|
|
|
|
|
checkedRows: IFollower[] = [];
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
page = 1;
|
|
|
|
|
|
|
|
perPage = 10;
|
|
|
|
|
2020-07-07 17:19:57 +02:00
|
|
|
timeAgoInstance: TimeAgo | null = null;
|
|
|
|
|
|
|
|
async mounted() {
|
|
|
|
const localeName = this.$i18n.locale;
|
|
|
|
const locale = await import(`javascript-time-ago/locale/${localeName}`);
|
|
|
|
TimeAgo.addLocale(locale);
|
|
|
|
this.timeAgoInstance = new TimeAgo(localeName);
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
toggle(row: object) {
|
|
|
|
this.table.toggleDetails(row);
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async onPageChange(page: number) {
|
|
|
|
this.page = page;
|
|
|
|
await this.$apollo.queries.relayFollowings.fetchMore({
|
|
|
|
variables: {
|
|
|
|
page: this.page,
|
|
|
|
limit: this.perPage,
|
|
|
|
},
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
|
|
|
if (!fetchMoreResult) return previousResult;
|
|
|
|
const newFollowings = fetchMoreResult.relayFollowings.elements;
|
|
|
|
return {
|
|
|
|
relayFollowings: {
|
|
|
|
__typename: previousResult.relayFollowings.__typename,
|
|
|
|
total: previousResult.relayFollowings.total,
|
|
|
|
elements: [...previousResult.relayFollowings.elements, ...newFollowings],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
static isInstance(actor: IActor): boolean {
|
|
|
|
return (
|
|
|
|
actor.type === ActorType.APPLICATION &&
|
|
|
|
(actor.preferredUsername === "relay" || actor.preferredUsername === actor.domain)
|
|
|
|
);
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
2020-07-07 17:19:57 +02:00
|
|
|
|
|
|
|
timeago(dateTime: string): string {
|
|
|
|
if (this.timeAgoInstance != null) {
|
|
|
|
return this.timeAgoInstance.format(new Date(dateTime));
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|