homepage/src/widgets/pyload/component.jsx

36 lines
1.2 KiB
React
Raw Normal View History

2022-11-06 11:05:31 +01:00
import { useTranslation } from 'next-i18next'
2022-11-06 11:45:25 +01:00
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
2022-11-06 11:05:31 +01:00
export default function Component({ service }) {
2022-11-06 11:45:25 +01:00
const { t } = useTranslation();
const { widget } = service;
const { data: pyloadData, error: pyloadError } = useWidgetAPI(widget, "status");
2022-11-06 11:05:31 +01:00
if (pyloadError || pyloadData?.error) {
2022-11-06 11:45:25 +01:00
return <Container error={t("widget.api_error")} />;
2022-11-06 11:05:31 +01:00
}
if (!pyloadData) {
return (
<Container service={service}>
<Block label="pyload.speed" />
<Block label="pyload.active" />
<Block label="pyload.queue" />
<Block label="pyload.total" />
</Container>
);
}
2022-11-06 11:05:31 +01:00
return (
<Container service={service}>
<Block label="pyload.speed" value={t("common.bitrate", { value: pyloadData.speed })} />
<Block label="pyload.active" value={t("common.number", { value: pyloadData.active })} />
<Block label="pyload.queue" value={t("common.number", { value: pyloadData.queue })} />
<Block label="pyload.total" value={t("common.number", { value: pyloadData.total })} />
</Container>
2022-11-06 11:45:25 +01:00
);
2022-11-06 11:05:31 +01:00
}