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) {
|
2023-04-30 19:09:37 -04:00
|
|
|
return <Container service={service} error={plexAPIError} />;
|
2022-10-10 00:31:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!plexData) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="plex.streams" />
|
2023-04-27 10:12:12 +02:00
|
|
|
<Block label="plex.albums" />
|
2022-10-10 00:31:50 -07:00
|
|
|
<Block label="plex.movies" />
|
|
|
|
<Block label="plex.tv" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="plex.streams" value={t("common.number", { value: plexData.streams })} />
|
2023-04-27 10:12:12 +02:00
|
|
|
<Block label="plex.albums" value={t("common.number", { value: plexData.albums })} />
|
2022-10-10 00:31:50 -07:00
|
|
|
<Block label="plex.movies" value={t("common.number", { value: plexData.movies })} />
|
|
|
|
<Block label="plex.tv" value={t("common.number", { value: plexData.tv })} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|