2022-10-10 00:31:50 -07:00
|
|
|
import { useTranslation } from "next-i18next";
|
2022-10-10 01:01:13 -07:00
|
|
|
|
2022-10-10 00:31:50 -07:00
|
|
|
import Block from "components/services/widget/block";
|
|
|
|
import Container from "components/services/widget/container";
|
2022-11-07 09:24:15 -08:00
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
2022-10-10 00:31:50 -07:00
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { widget } = service;
|
|
|
|
|
2022-11-07 09:24:15 -08:00
|
|
|
const { data: plexData, error: plexAPIError } = useWidgetAPI(widget, "unified", {
|
2022-10-10 00:31:50 -07:00
|
|
|
refreshInterval: 5000,
|
|
|
|
});
|
|
|
|
|
2022-11-07 09:24:15 -08:00
|
|
|
if (plexAPIError) {
|
|
|
|
return <Container error={plexAPIError} />;
|
2022-10-10 00:31:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!plexData) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="plex.streams" />
|
|
|
|
<Block label="plex.movies" />
|
|
|
|
<Block label="plex.tv" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="plex.streams" value={t("common.number", { value: plexData.streams })} />
|
|
|
|
<Block label="plex.movies" value={t("common.number", { value: plexData.movies })} />
|
|
|
|
<Block label="plex.tv" value={t("common.number", { value: plexData.tv })} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|