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";
|
|
|
|
|
2024-08-23 22:28:37 -04:00
|
|
|
const ROMM_DEFAULT_FIELDS = ["platforms", "totalRoms", "saves", "states"];
|
|
|
|
const MAX_ALLOWED_FIELDS = 4;
|
|
|
|
|
2024-01-20 07:36:44 +00:00
|
|
|
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) {
|
2024-08-23 22:28:37 -04:00
|
|
|
return <Container service={service} error={responseError} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!widget.fields?.length > 0) {
|
|
|
|
widget.fields = ROMM_DEFAULT_FIELDS;
|
|
|
|
} else if (widget.fields.length > MAX_ALLOWED_FIELDS) {
|
|
|
|
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!response) {
|
2024-01-20 07:36:44 +00:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2024-08-23 22:28:37 -04:00
|
|
|
<Block label="romm.platforms" />
|
|
|
|
<Block label="romm.totalRoms" />
|
|
|
|
<Block label="romm.saves" />
|
|
|
|
<Block label="romm.states" />
|
|
|
|
<Block label="romm.screenshots" />
|
|
|
|
<Block label="romm.totalfilesize" />
|
2024-01-20 07:36:44 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2024-08-23 22:28:37 -04:00
|
|
|
<Block label="romm.platforms" value={t("common.number", { value: response.PLATFORMS })} />
|
|
|
|
<Block label="romm.totalRoms" value={t("common.number", { value: response.ROMS })} />
|
|
|
|
<Block label="romm.saves" value={t("common.number", { value: response.SAVES })} />
|
|
|
|
<Block label="romm.states" value={t("common.number", { value: response.STATES })} />
|
|
|
|
<Block label="romm.screenshots" value={t("common.number", { value: response.SCREENSHOTS })} />
|
|
|
|
<Block label="romm.totalfilesize" value={t("common.bytes", { value: response.FILESIZE })} />
|
2024-01-20 07:36:44 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|