From f851085ebfc186b449b531fbbdc59993e09ca9e1 Mon Sep 17 00:00:00 2001 From: Bryan <32176387+KillahB33@users.noreply.github.com> Date: Thu, 2 Feb 2023 22:48:40 -0500 Subject: [PATCH] Komga Widget (#922) Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- public/locales/en/common.json | 5 +++++ src/widgets/components.js | 1 + src/widgets/komga/component.jsx | 37 +++++++++++++++++++++++++++++++++ src/widgets/komga/widget.js | 30 ++++++++++++++++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 75 insertions(+) create mode 100644 src/widgets/komga/component.jsx create mode 100644 src/widgets/komga/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index f144182f6..3d9890f39 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -454,5 +454,10 @@ "uptime": "Uptime", "incident": "Incident", "m": "m" + }, + "komga": { + "libraries": "Libraries", + "series": "Series", + "books": "Books" } } \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 505807c48..f09dc16eb 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -21,6 +21,7 @@ const components = { jackett: dynamic(() => import("./jackett/component")), jellyfin: dynamic(() => import("./emby/component")), jellyseerr: dynamic(() => import("./jellyseerr/component")), + komga: dynamic(() => import("./komga/component")), lidarr: dynamic(() => import("./lidarr/component")), mastodon: dynamic(() => import("./mastodon/component")), medusa: dynamic(() => import("./medusa/component")), diff --git a/src/widgets/komga/component.jsx b/src/widgets/komga/component.jsx new file mode 100644 index 000000000..9d6c406f7 --- /dev/null +++ b/src/widgets/komga/component.jsx @@ -0,0 +1,37 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { t } = useTranslation(); + const { widget } = service; + + const { data: libraryData, error: libraryError } = useWidgetAPI(widget, "libraries"); + const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series"); + const { data: bookData, error: bookError } = useWidgetAPI(widget, "books"); + + if (libraryError || seriesError || bookError) { + const finalError = libraryError ?? seriesError ?? bookError; + return ; + } + + if (!libraryData || !seriesData || !bookData) { + return ( + + + + + + ); + } + + return ( + + + + + + ); +} \ No newline at end of file diff --git a/src/widgets/komga/widget.js b/src/widgets/komga/widget.js new file mode 100644 index 000000000..eb43883d5 --- /dev/null +++ b/src/widgets/komga/widget.js @@ -0,0 +1,30 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; +import { jsonArrayFilter } from "utils/proxy/api-helpers"; + +const widget = { + api: "{url}/api/v1/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + libraries: { + endpoint: "libraries", + map: (data) => ({ + total: jsonArrayFilter(data, (item) => !item.unavailable).length, + }), + }, + series: { + endpoint: "series", + validate: [ + "totalElements" + ] + }, + books: { + endpoint: "books", + validate: [ + "totalElements" + ] + }, + }, +}; + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 7da77a0a6..688f09a08 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -15,6 +15,7 @@ import hdhomerun from "./hdhomerun/widget"; import homebridge from "./homebridge/widget"; import jackett from "./jackett/widget"; import jellyseerr from "./jellyseerr/widget"; +import komga from "./komga/widget"; import lidarr from "./lidarr/widget"; import mastodon from "./mastodon/widget"; import medusa from "./medusa/widget"; @@ -79,6 +80,7 @@ const widgets = { jackett, jellyfin: emby, jellyseerr, + komga, lidarr, mastodon, medusa,