2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Vue, Ref } from "vue-property-decorator";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { IActor } from "@/types/actor";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { IFollower } from "@/types/actor/follower.model";
|
2020-10-27 09:13:17 +01:00
|
|
|
import { RELAY_FOLLOWERS, RELAY_FOLLOWINGS } from "@/graphql/admin";
|
|
|
|
import { Paginate } from "@/types/paginate";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ActorType } from "@/types/enums";
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2020-10-27 09:13:17 +01:00
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
relayFollowings: {
|
|
|
|
query: RELAY_FOLLOWINGS,
|
|
|
|
fetchPolicy: "cache-and-network",
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
page: this.followingsPage,
|
|
|
|
limit: this.perPage,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
relayFollowers: {
|
|
|
|
query: RELAY_FOLLOWERS,
|
|
|
|
fetchPolicy: "cache-and-network",
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
page: this.followersPage,
|
|
|
|
limit: this.perPage,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2019-12-03 11:29:51 +01:00
|
|
|
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
|
|
|
|
2020-10-27 09:13:17 +01:00
|
|
|
relayFollowers: Paginate<IFollower> = { elements: [], total: 0 };
|
|
|
|
|
|
|
|
relayFollowings: Paginate<IFollower> = { elements: [], total: 0 };
|
|
|
|
|
2019-12-03 11:29:51 +01:00
|
|
|
checkedRows: IFollower[] = [];
|
|
|
|
|
2020-10-27 09:13:17 +01:00
|
|
|
followingsPage = 1;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-10-27 09:13:17 +01:00
|
|
|
followersPage = 1;
|
|
|
|
|
2020-10-29 10:43:07 +01:00
|
|
|
perPage = 10;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
toggle(row: Record<string, unknown>): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.table.toggleDetails(row);
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 09:13:17 +01:00
|
|
|
async onFollowingsPageChange(page: number): Promise<void> {
|
|
|
|
this.followingsPage = page;
|
|
|
|
try {
|
|
|
|
await this.$apollo.queries.relayFollowings.fetchMore({
|
|
|
|
variables: {
|
|
|
|
page: this.followingsPage,
|
|
|
|
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,
|
2020-11-30 10:24:11 +01:00
|
|
|
elements: [
|
|
|
|
...previousResult.relayFollowings.elements,
|
|
|
|
...newFollowings,
|
|
|
|
],
|
2020-10-27 09:13:17 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onFollowersPageChange(page: number): Promise<void> {
|
|
|
|
this.followersPage = page;
|
|
|
|
try {
|
|
|
|
await this.$apollo.queries.relayFollowers.fetchMore({
|
|
|
|
variables: {
|
|
|
|
page: this.followersPage,
|
|
|
|
limit: this.perPage,
|
|
|
|
},
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
|
|
|
if (!fetchMoreResult) return previousResult;
|
|
|
|
const newFollowers = fetchMoreResult.relayFollowers.elements;
|
|
|
|
return {
|
|
|
|
relayFollowers: {
|
|
|
|
__typename: previousResult.relayFollowers.__typename,
|
|
|
|
total: previousResult.relayFollowers.total,
|
2020-11-30 10:24:11 +01:00
|
|
|
elements: [
|
|
|
|
...previousResult.relayFollowers.elements,
|
|
|
|
...newFollowers,
|
|
|
|
],
|
2020-10-27 09:13:17 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
static isInstance(actor: IActor): boolean {
|
|
|
|
return (
|
|
|
|
actor.type === ActorType.APPLICATION &&
|
2020-11-30 10:24:11 +01:00
|
|
|
(actor.preferredUsername === "relay" ||
|
|
|
|
actor.preferredUsername === actor.domain)
|
2020-02-18 08:57:00 +01:00
|
|
|
);
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
}
|