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 { InitialFetchRequest } from "../../interfaces";
11 import { FirstLoadService, I18NextService } from "../../services";
12 import { HttpService, RequestState } from "../../services/HttpService";
13 import { HtmlTags } from "../common/html-tags";
14 import { Spinner } from "../common/icon";
16 type InstancesData = RouteDataResponse<{
17 federatedInstancesResponse: GetFederatedInstancesResponse;
20 interface InstancesState {
21 instancesRes: RequestState<GetFederatedInstancesResponse>;
22 siteRes: GetSiteResponse;
23 isIsomorphic: boolean;
26 export class Instances extends Component<any, InstancesState> {
27 private isoData = setIsoData<InstancesData>(this.context);
28 state: InstancesState = {
29 instancesRes: { state: "empty" },
30 siteRes: this.isoData.site_res,
34 constructor(props: any, context: any) {
35 super(props, context);
37 // Only fetch the data if coming from another route
38 if (FirstLoadService.isFirstLoad) {
41 instancesRes: this.isoData.routeData.federatedInstancesResponse,
47 async componentDidMount() {
48 if (!this.state.isIsomorphic) {
49 await this.fetchInstances();
53 async fetchInstances() {
55 instancesRes: { state: "loading" },
59 instancesRes: await HttpService.client.getFederatedInstances({}),
63 static async fetchInitialData({
65 }: InitialFetchRequest): Promise<InstancesData> {
67 federatedInstancesResponse: await client.getFederatedInstances({}),
71 get documentTitle(): string {
72 return `${I18NextService.i18n.t("instances")} - ${
73 this.state.siteRes.site_view.site.name
78 switch (this.state.instancesRes.state) {
86 const instances = this.state.instancesRes.data.federated_instances;
89 <div className="col-md-6">
90 <h5>{I18NextService.i18n.t("linked_instances")}</h5>
91 {this.itemList(instances.linked)}
93 {instances.allowed && instances.allowed.length > 0 && (
94 <div className="col-md-6">
95 <h5>{I18NextService.i18n.t("allowed_instances")}</h5>
96 {this.itemList(instances.allowed)}
99 {instances.blocked && instances.blocked.length > 0 && (
100 <div className="col-md-6">
101 <h5>{I18NextService.i18n.t("blocked_instances")}</h5>
102 {this.itemList(instances.blocked)}
115 <div className="home-instances container-lg">
117 title={this.documentTitle}
118 path={this.context.router.route.match.url}
120 {this.renderInstances()}
125 itemList(items: Instance[]) {
126 return items.length > 0 ? (
127 <div className="table-responsive">
128 <table id="instances_table" className="table table-sm table-hover">
129 <thead className="pointer">
131 <th>{I18NextService.i18n.t("name")}</th>
132 <th>{I18NextService.i18n.t("software")}</th>
133 <th>{I18NextService.i18n.t("version")}</th>
140 <a href={`https://${i.domain}`} rel={relTags}>
144 <td>{i.software}</td>
152 <div>{I18NextService.i18n.t("none_found")}</div>