2023-03-05 23:34:46 -08:00
|
|
|
import Block from "components/services/widget/block";
|
2025-03-30 21:40:03 -07:00
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import { useTranslation } from "next-i18next";
|
2025-02-18 16:16:53 -08:00
|
|
|
|
2023-03-05 23:34:46 -08:00
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { widget } = service;
|
|
|
|
const { data: librariesData, error: librariesError } = useWidgetAPI(widget, "libraries");
|
|
|
|
|
|
|
|
if (librariesError) {
|
2023-04-30 19:09:37 -04:00
|
|
|
return <Container service={service} error={librariesError} />;
|
2023-03-05 23:34:46 -08:00
|
|
|
}
|
2023-10-17 23:26:55 -07:00
|
|
|
|
2023-03-05 23:34:46 -08:00
|
|
|
if (!librariesData) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="audiobookshelf.podcasts" />
|
|
|
|
<Block label="audiobookshelf.podcastsDuration" />
|
|
|
|
<Block label="audiobookshelf.books" />
|
|
|
|
<Block label="audiobookshelf.booksDuration" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
2023-10-17 23:26:55 -07:00
|
|
|
|
|
|
|
const podcastLibraries = librariesData.filter((l) => l.mediaType === "podcast");
|
|
|
|
const bookLibraries = librariesData.filter((l) => l.mediaType === "book");
|
2023-03-05 23:34:46 -08:00
|
|
|
|
|
|
|
const totalPodcasts = podcastLibraries.reduce((total, pL) => parseInt(pL.stats?.totalItems, 10) + total, 0);
|
|
|
|
const totalBooks = bookLibraries.reduce((total, bL) => parseInt(bL.stats?.totalItems, 10) + total, 0);
|
|
|
|
|
|
|
|
const totalPodcastsDuration = podcastLibraries.reduce((total, pL) => parseFloat(pL.stats?.totalDuration) + total, 0);
|
|
|
|
const totalBooksDuration = bookLibraries.reduce((total, bL) => parseFloat(bL.stats?.totalDuration) + total, 0);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="audiobookshelf.podcasts" value={t("common.number", { value: totalPodcasts })} />
|
2023-10-17 23:26:55 -07:00
|
|
|
<Block
|
|
|
|
label="audiobookshelf.podcastsDuration"
|
2024-10-31 22:09:23 -07:00
|
|
|
value={t("common.duration", {
|
|
|
|
value: totalPodcastsDuration,
|
2023-10-17 23:26:55 -07:00
|
|
|
})}
|
|
|
|
/>
|
2023-03-05 23:34:46 -08:00
|
|
|
<Block label="audiobookshelf.books" value={t("common.number", { value: totalBooks })} />
|
2023-10-17 23:26:55 -07:00
|
|
|
<Block
|
|
|
|
label="audiobookshelf.booksDuration"
|
2024-11-17 16:16:18 -08:00
|
|
|
value={t("common.duration", {
|
|
|
|
value: totalBooksDuration,
|
2023-10-17 23:26:55 -07:00
|
|
|
})}
|
|
|
|
/>
|
2023-03-05 23:34:46 -08:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|