homepage/src/widgets/mastodon/component.jsx

37 lines
1.1 KiB
React
Raw Normal View History

2022-09-20 03:41:10 +02:00
import useSWR from "swr";
2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-09-20 03:41:10 +02:00
2022-09-26 02:23:02 +03:00
import Widget from "components/services/widgets/widget";
import Block from "components/services/widgets/block";
import { formatProxyUrl } from "utils/proxy/api-helpers";
2022-09-20 03:41:10 +02:00
2022-09-26 02:23:02 +03:00
export default function Component({ service }) {
2022-09-20 03:41:10 +02:00
const { t } = useTranslation();
const config = service.widget;
2022-09-25 19:43:47 +03:00
const { data: statsData, error: statsError } = useSWR(formatProxyUrl(config, `instance`));
2022-09-20 03:41:10 +02:00
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>
2022-09-25 19:43:47 +03:00
<Block label={t("mastodon.user_count")} value={t("common.number", { value: statsData.stats.user_count })} />
2022-09-20 03:41:10 +02:00
<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>
);
}