From 2a24277757abb9f3b2ffa004705db1d9205e3601 Mon Sep 17 00:00:00 2001 From: Ulysse Mensa Date: Mon, 16 Jan 2023 22:38:44 +0100 Subject: [PATCH] Add Medusa widget --- public/locales/en/common.json | 7 +++++- src/widgets/components.js | 1 + src/widgets/medusa/component.jsx | 39 ++++++++++++++++++++++++++++++++ src/widgets/medusa/widget.js | 23 +++++++++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/widgets/medusa/component.jsx create mode 100644 src/widgets/medusa/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 032c1dfef..1f7464f74 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -255,6 +255,11 @@ "status_count": "Posts", "domain_count": "Domains" }, + "medusa": { + "wanted": "Wanted", + "queued": "Queued", + "series": "Series" + }, "miniflux": { "read": "Read", "unread": "Unread" @@ -413,4 +418,4 @@ "wanUpload": "WAN Upload", "wanDownload": "WAN Download" } -} +} \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 10277732f..98afefbf6 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -21,6 +21,7 @@ const components = { jellyseerr: dynamic(() => import("./jellyseerr/component")), lidarr: dynamic(() => import("./lidarr/component")), mastodon: dynamic(() => import("./mastodon/component")), + medusa: dynamic(() => import("./medusa/component")), miniflux: dynamic(() => import("./miniflux/component")), mikrotik: dynamic(() => import("./mikrotik/component")), navidrome: dynamic(() => import("./navidrome/component")), diff --git a/src/widgets/medusa/component.jsx b/src/widgets/medusa/component.jsx new file mode 100644 index 000000000..47bad7d4d --- /dev/null +++ b/src/widgets/medusa/component.jsx @@ -0,0 +1,39 @@ +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: statsData, error: statsError } = useWidgetAPI(widget, "stats"); + const { data: futureData, error: futureError } = useWidgetAPI(widget, "future"); + + if (statsError || futureError) { + const finalError = statsError ?? futureError; + return ; + } + + if (!statsData || !futureData) { + return ( + + + + + + ); + } + + const { later, missed, soon, today } = futureData.data; + const future = later.length + missed.length + soon.length + today.length; + + return ( + + + + + + ); +} diff --git a/src/widgets/medusa/widget.js b/src/widgets/medusa/widget.js new file mode 100644 index 000000000..bb6f47857 --- /dev/null +++ b/src/widgets/medusa/widget.js @@ -0,0 +1,23 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/v1/{key}/{endpoint}/", + proxyHandler: genericProxyHandler, + + mappings: { + stats: { + endpoint: "?cmd=shows.stats", + validate: [ + "data" + ] + }, + future: { + endpoint: "?cmd=future", + validate: [ + "data" + ] + } + } +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 3e73e55f3..b13dd9644 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -16,6 +16,7 @@ import jackett from "./jackett/widget"; import jellyseerr from "./jellyseerr/widget"; import lidarr from "./lidarr/widget"; import mastodon from "./mastodon/widget"; +import medusa from "./medusa/widget"; import miniflux from "./miniflux/widget"; import mikrotik from "./mikrotik/widget"; import navidrome from "./navidrome/widget"; @@ -73,6 +74,7 @@ const widgets = { jellyseerr, lidarr, mastodon, + medusa, miniflux, mikrotik, navidrome,