homepage/src/widgets/mastodon/component.jsx

36 lines
1.1 KiB
React
Raw Normal View History

2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-09-20 03:41:10 +02:00
2022-09-26 15:25:10 +03:00
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
2022-09-27 22:59:14 +03:00
import useWidgetAPI from "utils/proxy/use-widget-api";
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();
2022-09-27 22:59:14 +03:00
const { widget } = service;
2022-09-20 03:41:10 +02:00
2022-09-27 22:59:14 +03:00
const { data: statsData, error: statsError } = useWidgetAPI(widget, "instance");
2022-09-20 03:41:10 +02:00
2022-11-07 09:24:15 -08:00
if (statsError) {
return <Container error={statsError} />;
2022-09-20 03:41:10 +02:00
}
if (!statsData) {
return (
<Container service={service}>
<Block label="mastodon.user_count" />
<Block label="mastodon.status_count" />
<Block label="mastodon.domain_count" />
2022-09-26 15:25:10 +03:00
</Container>
2022-09-20 03:41:10 +02:00
);
}
return (
<Container service={service}>
<Block label="mastodon.user_count" value={t("common.number", { value: statsData.stats.user_count })} />
<Block label="mastodon.status_count" value={t("common.number", { value: statsData.stats.status_count })} />
<Block label="mastodon.domain_count" value={t("common.number", { value: statsData.stats.domain_count })} />
2022-09-26 15:25:10 +03:00
</Container>
2022-09-20 03:41:10 +02:00
);
}