feat: add books field to jellyfin widget

This commit is contained in:
AdamWHY2K 2024-10-26 15:16:18 +01:00
parent 7cbba1ff90
commit 65b57ea7d0
3 changed files with 12 additions and 6 deletions

View File

@ -7,7 +7,7 @@ Learn more about [Jellyfin](https://github.com/jellyfin/jellyfin).
You can create an API key from inside Jellyfin at `Settings > Advanced > Api Keys`. You can create an API key from inside Jellyfin at `Settings > Advanced > Api Keys`.
As of v0.6.11 the widget supports fields `["movies", "series", "episodes", "songs"]`. These blocks are disabled by default but can be enabled with the `enableBlocks` option, and the "Now Playing" feature (enabled by default) can be disabled with the `enableNowPlaying` option. As of v0.6.11 the widget supports fields `["movies", "series", "episodes", "songs", "books"]`. These blocks are disabled by default but can be enabled with the `enableBlocks` option, and the "Now Playing" feature (enabled by default) can be disabled with the `enableNowPlaying` option.
```yaml ```yaml
widget: widget:

View File

@ -105,7 +105,8 @@
"movies": "Movies", "movies": "Movies",
"series": "Series", "series": "Series",
"episodes": "Episodes", "episodes": "Episodes",
"songs": "Songs" "songs": "Songs",
"books": "Books"
}, },
"esphome": { "esphome": {
"offline": "Offline", "offline": "Offline",

View File

@ -175,26 +175,31 @@ function SessionEntry({ playCommand, session, enableUser, showEpisodeNumber }) {
function CountBlocks({ service, countData }) { function CountBlocks({ service, countData }) {
const { t } = useTranslation(); const { t } = useTranslation();
// allows filtering // allows filtering
// eslint-disable-next-line no-param-reassign const isJellyfin = service.widget?.type === "jellyfin";
if (service.widget?.type === "jellyfin") service.widget.type = "emby"; // Create a new service object instead of modifying the original
const modifiedService = isJellyfin
? { ...service, widget: { ...service.widget, type: "emby" }}
: service;
if (!countData) { if (!countData) {
return ( return (
<Container service={service}> <Container service={modifiedService}>
<Block label="emby.movies" /> <Block label="emby.movies" />
<Block label="emby.series" /> <Block label="emby.series" />
<Block label="emby.episodes" /> <Block label="emby.episodes" />
<Block label="emby.songs" /> <Block label="emby.songs" />
{isJellyfin && <Block label="emby.books" />}
</Container> </Container>
); );
} }
return ( return (
<Container service={service}> <Container service={modifiedService}>
<Block label="emby.movies" value={t("common.number", { value: countData.MovieCount })} /> <Block label="emby.movies" value={t("common.number", { value: countData.MovieCount })} />
<Block label="emby.series" value={t("common.number", { value: countData.SeriesCount })} /> <Block label="emby.series" value={t("common.number", { value: countData.SeriesCount })} />
<Block label="emby.episodes" value={t("common.number", { value: countData.EpisodeCount })} /> <Block label="emby.episodes" value={t("common.number", { value: countData.EpisodeCount })} />
<Block label="emby.songs" value={t("common.number", { value: countData.SongCount })} /> <Block label="emby.songs" value={t("common.number", { value: countData.SongCount })} />
{isJellyfin && <Block label="emby.books" value={t("common.number", { value: countData.BookCount })} />}
</Container> </Container>
); );
} }