2022-06-21 21:42:29 +00:00
|
|
|
import { None } from "@sniptt/monads";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
|
|
|
import { GetSiteResponse } from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2022-02-24 15:31:44 +00:00
|
|
|
import { relTags, setIsoData } from "../../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface InstancesState {
|
|
|
|
siteRes: GetSiteResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Instances extends Component<any, InstancesState> {
|
2020-09-07 22:24:48 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
private emptyState: InstancesState = {
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.state = this.emptyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.siteRes.site_view.match({
|
|
|
|
some: siteView => `${i18n.t("instances")} - ${siteView.site.name}`,
|
|
|
|
none: "",
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.siteRes.federated_instances.match({
|
|
|
|
some: federated_instances => (
|
2021-02-01 18:08:45 +00:00
|
|
|
<div class="container">
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
2022-06-21 21:42:29 +00:00
|
|
|
description={None}
|
|
|
|
image={None}
|
2021-02-01 18:08:45 +00:00
|
|
|
/>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
2021-02-22 02:39:04 +00:00
|
|
|
<h5>{i18n.t("linked_instances")}</h5>
|
2021-02-01 18:08:45 +00:00
|
|
|
{this.itemList(federated_instances.linked)}
|
|
|
|
</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
{federated_instances.allowed.match({
|
|
|
|
some: allowed =>
|
|
|
|
allowed.length > 0 && (
|
|
|
|
<div class="col-md-6">
|
|
|
|
<h5>{i18n.t("allowed_instances")}</h5>
|
|
|
|
{this.itemList(allowed)}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
|
|
|
{federated_instances.blocked.match({
|
|
|
|
some: blocked =>
|
|
|
|
blocked.length > 0 && (
|
|
|
|
<div class="col-md-6">
|
|
|
|
<h5>{i18n.t("blocked_instances")}</h5>
|
|
|
|
{this.itemList(blocked)}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2021-02-01 18:08:45 +00:00
|
|
|
</div>
|
2020-09-07 22:24:48 +00:00
|
|
|
</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
});
|
2021-02-01 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
itemList(items: string[]) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let noneFound = <div>{i18n.t("none_found")}</div>;
|
2021-02-01 18:08:45 +00:00
|
|
|
return items.length > 0 ? (
|
|
|
|
<ul>
|
|
|
|
{items.map(i => (
|
|
|
|
<li>
|
2022-02-24 15:31:44 +00:00
|
|
|
<a href={`https://${i}`} rel={relTags}>
|
2021-02-01 18:08:45 +00:00
|
|
|
{i}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
) : (
|
2022-06-21 21:42:29 +00:00
|
|
|
noneFound
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|