2024-04-23 22:13:53 +01:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2024-01-20 07:36:44 +00: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 }) {
|
|
|
|
const { widget } = service;
|
2024-04-23 22:13:53 +01:00
|
|
|
const { t } = useTranslation();
|
2024-01-20 07:36:44 +00:00
|
|
|
|
|
|
|
const { data: response, error: responseError } = useWidgetAPI(widget, "statistics");
|
|
|
|
|
|
|
|
if (responseError) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="Error" value={responseError.message} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseError) {
|
|
|
|
return <Container service={service} error={responseError} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response) {
|
|
|
|
const platforms = response.filter((x) => x.rom_count !== 0).length;
|
|
|
|
const totalRoms = response.reduce((total, stat) => total + stat.rom_count, 0);
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2024-04-23 22:13:53 +01:00
|
|
|
<Block label="romm.platforms" value={t("common.number", { value: platforms })} />
|
|
|
|
<Block label="romm.totalRoms" value={t("common.number", { value: totalRoms })} />
|
2024-01-20 07:36:44 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|