2024-08-25 00:02:47 -04:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2023-08-09 15:13:17 -04:00
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import Block from "components/services/widget/block";
|
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
2024-08-25 00:02:47 -04:00
|
|
|
const { t } = useTranslation();
|
2023-08-09 15:13:17 -04:00
|
|
|
const { widget } = service;
|
2024-08-25 00:02:47 -04:00
|
|
|
const version = widget.version ?? 1;
|
|
|
|
const { data, error } = useWidgetAPI(widget, version === 1 ? "statisticsv1" : "statisticsv2");
|
2023-08-09 15:13:17 -04:00
|
|
|
|
2024-08-25 00:02:47 -04:00
|
|
|
if (error) {
|
|
|
|
return <Container service={service} error={error} />;
|
2023-08-09 15:13:17 -04:00
|
|
|
}
|
|
|
|
|
2024-08-25 00:02:47 -04:00
|
|
|
if (!data) {
|
2023-08-09 15:13:17 -04:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="mealie.recipes" />
|
|
|
|
<Block label="mealie.users" />
|
|
|
|
<Block label="mealie.categories" />
|
|
|
|
<Block label="mealie.tags" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2024-08-25 00:02:47 -04:00
|
|
|
<Block label="mealie.recipes" value={t("common.number", { value: data.totalRecipes })} />
|
|
|
|
<Block label="mealie.users" value={t("common.number", { value: data.totalUsers })} />
|
|
|
|
<Block label="mealie.categories" value={t("common.number", { value: data.totalCategories })} />
|
|
|
|
<Block label="mealie.tags" value={t("common.number", { value: data.totalTags })} />
|
2023-08-09 15:13:17 -04:00
|
|
|
</Container>
|
|
|
|
);
|
2023-10-17 23:26:55 -07:00
|
|
|
}
|