1 import { setIsoData } from "@utils/app";
2 import { RouteDataResponse } from "@utils/types";
3 import { Component } from "inferno";
5 GetFederatedInstancesResponse,
8 } from "lemmy-js-client";
9 import { relTags } from "../../config";
10 import { i18n } from "../../i18next";
11 import { InitialFetchRequest } from "../../interfaces";
12 import { FirstLoadService } from "../../services/FirstLoadService";
13 import { HttpService, RequestState } from "../../services/HttpService";
14 import { HtmlTags } from "../common/html-tags";
15 import { Spinner } from "../common/icon";
17 type InstancesData = RouteDataResponse<{
18 federatedInstancesResponse: GetFederatedInstancesResponse;
21 interface InstancesState {
22 instancesRes: RequestState<GetFederatedInstancesResponse>;
23 siteRes: GetSiteResponse;
24 isIsomorphic: boolean;
27 export class Instances extends Component<any, InstancesState> {
28 private isoData = setIsoData<InstancesData>(this.context);
29 state: InstancesState = {
30 instancesRes: { state: "empty" },
31 siteRes: this.isoData.site_res,
35 constructor(props: any, context: any) {
36 super(props, context);
38 // Only fetch the data if coming from another route
39 if (FirstLoadService.isFirstLoad) {
42 instancesRes: this.isoData.routeData.federatedInstancesResponse,
48 async componentDidMount() {
49 if (!this.state.isIsomorphic) {
50 await this.fetchInstances();
54 async fetchInstances() {
56 instancesRes: { state: "loading" },
60 instancesRes: await HttpService.client.getFederatedInstances({}),
64 static async fetchInitialData({
66 }: InitialFetchRequest): Promise<InstancesData> {
68 federatedInstancesResponse: await client.getFederatedInstances({}),
72 get documentTitle(): string {
73 return `${i18n.t("instances")} - ${this.state.siteRes.site_view.site.name}`;
77 switch (this.state.instancesRes.state) {
85 const instances = this.state.instancesRes.data.federated_instances;
88 <div className="col-md-6">
89 <h5>{i18n.t("linked_instances")}</h5>
90 {this.itemList(instances.linked)}
92 {instances.allowed && instances.allowed.length > 0 && (
93 <div className="col-md-6">
94 <h5>{i18n.t("allowed_instances")}</h5>
95 {this.itemList(instances.allowed)}
98 {instances.blocked && instances.blocked.length > 0 && (
99 <div className="col-md-6">
100 <h5>{i18n.t("blocked_instances")}</h5>
101 {this.itemList(instances.blocked)}
114 <div className="home-instances container-lg">
116 title={this.documentTitle}
117 path={this.context.router.route.match.url}
119 {this.renderInstances()}
124 itemList(items: Instance[]) {
125 return items.length > 0 ? (
126 <div className="table-responsive">
127 <table id="instances_table" className="table table-sm table-hover">
128 <thead className="pointer">
130 <th>{i18n.t("name")}</th>
131 <th>{i18n.t("software")}</th>
132 <th>{i18n.t("version")}</th>
139 <a href={`https://${i.domain}`} rel={relTags}>
143 <td>{i.software}</td>
151 <div>{i18n.t("none_found")}</div>