1 import { Component } from "inferno";
3 GetFederatedInstancesResponse,
6 } from "lemmy-js-client";
7 import { i18n } from "../../i18next";
8 import { InitialFetchRequest } from "../../interfaces";
9 import { FirstLoadService } from "../../services/FirstLoadService";
10 import { HttpService, RequestState } from "../../services/HttpService";
11 import { relTags, setIsoData } from "../../utils";
12 import { HtmlTags } from "../common/html-tags";
13 import { Spinner } from "../common/icon";
15 interface InstancesState {
16 instancesRes: RequestState<GetFederatedInstancesResponse>;
17 siteRes: GetSiteResponse;
18 isIsomorphic: boolean;
21 export class Instances extends Component<any, InstancesState> {
22 private isoData = setIsoData(this.context);
23 state: InstancesState = {
24 instancesRes: { state: "empty" },
25 siteRes: this.isoData.site_res,
29 constructor(props: any, context: any) {
30 super(props, context);
32 // Only fetch the data if coming from another route
33 if (FirstLoadService.isFirstLoad) {
36 instancesRes: this.isoData.routeData[0],
42 async componentDidMount() {
43 if (!this.state.isIsomorphic) {
44 await this.fetchInstances();
48 async fetchInstances() {
50 instancesRes: { state: "loading" },
54 instancesRes: await HttpService.client.getFederatedInstances({}),
58 static fetchInitialData(
59 req: InitialFetchRequest
60 ): Promise<RequestState<any>>[] {
61 return [req.client.getFederatedInstances({})];
64 get documentTitle(): string {
65 return `${i18n.t("instances")} - ${this.state.siteRes.site_view.site.name}`;
69 switch (this.state.instancesRes.state) {
77 const instances = this.state.instancesRes.data.federated_instances;
80 <div className="col-md-6">
81 <h5>{i18n.t("linked_instances")}</h5>
82 {this.itemList(instances.linked)}
84 {instances.allowed && instances.allowed.length > 0 && (
85 <div className="col-md-6">
86 <h5>{i18n.t("allowed_instances")}</h5>
87 {this.itemList(instances.allowed)}
90 {instances.blocked && instances.blocked.length > 0 && (
91 <div className="col-md-6">
92 <h5>{i18n.t("blocked_instances")}</h5>
93 {this.itemList(instances.blocked)}
106 <div className="container-lg">
108 title={this.documentTitle}
109 path={this.context.router.route.match.url}
111 {this.renderInstances()}
116 itemList(items: Instance[]) {
117 return items.length > 0 ? (
118 <div className="table-responsive">
119 <table id="instances_table" className="table table-sm table-hover">
120 <thead className="pointer">
122 <th>{i18n.t("name")}</th>
123 <th>{i18n.t("software")}</th>
124 <th>{i18n.t("version")}</th>
131 <a href={`https://${i.domain}`} rel={relTags}>
135 <td>{i.software}</td>
143 <div>{i18n.t("none_found")}</div>