From eaf7ba608b5f9707950ec5d7f16fbcd58e84d099 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:50:28 -0700 Subject: [PATCH] Fix blocks for emby/jellyfin, support enable/disable --- public/locales/en/common.json | 6 +- src/utils/config/service-helpers.js | 8 +- src/widgets/emby/component.jsx | 173 ++++++++++++++-------------- 3 files changed, 101 insertions(+), 86 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index a9d6ed34c..db5ffe46b 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -72,7 +72,11 @@ "playing": "Playing", "transcoding": "Transcoding", "bitrate": "Bitrate", - "no_active": "No Active Streams" + "no_active": "No Active Streams", + "movies": "Movies", + "series": "Series", + "episodes": "Episodes", + "songs": "Songs" }, "flood": { "download": "Download", diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 49401ee63..317c0f3c3 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -247,7 +247,9 @@ export function cleanServiceGroups(groups) { namespace, // kubernetes widget app, podSelector, - wan // opnsense widget + wan, // opnsense widget, + enableBlocks, // emby/jellyfin + enableNowPlaying } = cleanedService.widget; const fieldsList = typeof fields === 'string' ? JSON.parse(fields) : fields; @@ -278,6 +280,10 @@ export function cleanServiceGroups(groups) { if (type === "opnsense") { if (wan) cleanedService.widget.wan = wan; } + if (type === "emby" || type === "jellyfin") { + if (enableBlocks) cleanedService.widget.enableBlocks = enableBlocks === 'true'; + if (enableNowPlaying) cleanedService.widget.enableNowPlaying = enableNowPlaying === 'true'; + } } return cleanedService; diff --git a/src/widgets/emby/component.jsx b/src/widgets/emby/component.jsx index a8d4f6b26..3f70a79d6 100644 --- a/src/widgets/emby/component.jsx +++ b/src/widgets/emby/component.jsx @@ -149,6 +149,33 @@ function SessionEntry({ playCommand, session }) { ); } +function CountBlocks({ service, countData }) { + const { t } = useTranslation(); + // allows filtering + // eslint-disable-next-line no-param-reassign + if (service.widget?.type === 'jellyfin') service.widget.type = 'emby' + + if (!countData) { + return ( + + + + + + + ) + } + + return ( + + + + + + + ) +} + export default function Component({ service }) { const { t } = useTranslation(); @@ -179,114 +206,92 @@ export default function Component({ service }) { } if (sessionsError || countError) { - return ; + return ; } - if (!sessionsData && countData) { + const enableBlocks = service.widget?.enableBlocks + const enableNowPlaying = service.widget?.enableNowPlaying ?? true + + if (!sessionsData || !countData) { return ( <> - - - - - - -
+ {enableBlocks && } + {enableNowPlaying &&
-
-
-
+
} ); } - if (!sessionsData) { - return ( -
-
- - + if (enableNowPlaying) { + const playing = sessionsData + .filter((session) => session?.NowPlayingItem) + .sort((a, b) => { + if (a.PlayState.PositionTicks > b.PlayState.PositionTicks) { + return 1; + } + if (a.PlayState.PositionTicks < b.PlayState.PositionTicks) { + return -1; + } + return 0; + }); + + if (playing.length === 0) { + return ( + <> + {enableBlocks && } +
+
+ {t("emby.no_active")} +
+
+ - +
-
- - + + ); + } + + if (playing.length === 1) { + const session = playing[0]; + return ( + <> + {enableBlocks && } +
+ handlePlayCommand(currentSession, command)} + session={session} + />
-
- ); - } - - const playing = sessionsData - .filter((session) => session?.NowPlayingItem) - .sort((a, b) => { - if (a.PlayState.PositionTicks > b.PlayState.PositionTicks) { - return 1; - } - if (a.PlayState.PositionTicks < b.PlayState.PositionTicks) { - return -1; - } - return 0; - }); - - if (playing.length === 0 && countData) { + + ); + } + + if (playing.length === -1) return ( <> - - - - - - + {enableBlocks && }
-
- {t("emby.no_active")} -
-
- - -
+ {playing.map((session) => ( + handlePlayCommand(currentSession, command)} + session={session} + /> + ))}
); } - if (playing.length === 1 && countData) { - const session = playing[0]; + if (enableBlocks) { return ( - <> - - - - - - -
- handlePlayCommand(currentSession, command)} - session={session} - /> -
- - ); + + ) } - - if (countData && playing.length === -1) - return ( - <> - - - - - - -
- {playing.map((session) => ( - handlePlayCommand(currentSession, command)} - session={session} - /> - ))} -
- - ); }