Merge branch 'main' into feature/widget_strelaysrv

This commit is contained in:
Ben Phelps
2022-09-21 09:05:42 +03:00
committed by GitHub
33 changed files with 433 additions and 38 deletions

View File

@@ -1,10 +1,13 @@
import Image from "next/future/image";
import { useContext } from "react";
import { Disclosure } from "@headlessui/react";
import Status from "./status";
import Widget from "./widget";
import Docker from "./widgets/service/docker";
import { SettingsContext } from "utils/settings-context";
function resolveIcon(icon) {
if (icon.startsWith("http")) {
return `/api/proxy?url=${encodeURIComponent(icon)}`;
@@ -23,6 +26,7 @@ function resolveIcon(icon) {
export default function Item({ service }) {
const hasLink = service.href && service.href !== "#";
const { settings } = useContext(SettingsContext);
return (
<li key={service.name}>
@@ -37,7 +41,7 @@ export default function Item({ service }) {
(hasLink ? (
<a
href={service.href}
target="_blank"
target={settings.target ?? "_blank"}
rel="noreferrer"
className="flex-shrink-0 flex items-center justify-center w-12 "
>
@@ -52,7 +56,7 @@ export default function Item({ service }) {
{hasLink ? (
<a
href={service.href}
target="_blank"
target={settings.target ?? "_blank"}
rel="noreferrer"
className="flex-1 flex items-center justify-between rounded-r-md "
>

View File

@@ -28,6 +28,7 @@ import Prowlarr from "./widgets/service/prowlarr";
import Jackett from "./widgets/service/jackett";
import AdGuard from "./widgets/service/adguard";
import StRelaySrv from "./widgets/service/strelaysrv";
import Mastodon from "./widgets/service/mastodon";
const widgetMappings = {
docker: Docker,
@@ -58,6 +59,7 @@ const widgetMappings = {
jackett: Jackett,
adguard: AdGuard,
strelaysrv: StRelaySrv,
mastodon: Mastodon,
};
export default function Widget({ service }) {

View File

@@ -0,0 +1,37 @@
import useSWR from "swr";
import { useTranslation } from "react-i18next";
import Widget from "../widget";
import Block from "../block";
import { formatApiUrl } from "utils/api-helpers";
export default function Mastodon({ service }) {
const { t } = useTranslation();
const config = service.widget;
const { data: statsData, error: statsError } = useSWR(formatApiUrl(config, `instance`));
if (statsError) {
return <Widget error={t("widget.api_error")} />;
}
if (!statsData) {
return (
<Widget>
<Block label={t("mastodon.user_count")} />
<Block label={t("mastodon.status_count")} />
<Block label={t("mastodon.domain_count")} />
</Widget>
);
}
return (
<Widget>
<Block label={t("mastodon.user_count")} value={t("common.number", { value: statsData.stats.user_count })} />
<Block label={t("mastodon.status_count")} value={t("common.number", { value: statsData.stats.status_count })} />
<Block label={t("mastodon.domain_count")} value={t("common.number", { value: statsData.stats.domain_count })} />
</Widget>
);
}