From 58e8109856754ca05672f86a933aabe0c43d2e6b Mon Sep 17 00:00:00 2001 From: KillahBee Date: Fri, 3 Feb 2023 15:51:52 -0500 Subject: [PATCH] adding working mylar --- public/locales/en/common.json | 5 +++++ src/widgets/components.js | 1 + src/widgets/mylar/component.jsx | 40 +++++++++++++++++++++++++++++++++ src/widgets/mylar/widget.js | 20 +++++++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 68 insertions(+) create mode 100644 src/widgets/mylar/component.jsx create mode 100644 src/widgets/mylar/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index f144182f6..77912d460 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -454,5 +454,10 @@ "uptime": "Uptime", "incident": "Incident", "m": "m" + }, + "mylar": { + "series": "Series", + "issues": "Issues", + "wanted": "Wanted" } } \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 505807c48..11f7812b9 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -27,6 +27,7 @@ const components = { miniflux: dynamic(() => import("./miniflux/component")), mikrotik: dynamic(() => import("./mikrotik/component")), moonraker: dynamic(() => import("./moonraker/component")), + mylar: dynamic(() => import("./mylar/component")), navidrome: dynamic(() => import("./navidrome/component")), nextdns: dynamic(() => import("./nextdns/component")), npm: dynamic(() => import("./npm/component")), diff --git a/src/widgets/mylar/component.jsx b/src/widgets/mylar/component.jsx new file mode 100644 index 000000000..e284c93fa --- /dev/null +++ b/src/widgets/mylar/component.jsx @@ -0,0 +1,40 @@ +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: seriesData, error: seriesError } = useWidgetAPI(widget, "series"); + const { data: issuesData, error: issuesError } = useWidgetAPI(widget, "issues"); + const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted"); + + if (seriesError || issuesError || wantedError) { + const finalError = seriesError ?? issuesError ?? wantedError; + return ; + } + + if (!seriesData || !issuesData || !wantedData) { + return ( + + + + + + ); + } + + const totalIssues = issuesData.data.reduce((acc, series) => acc + series.totalIssues, 0); + + return ( + + + + + + ); +} \ No newline at end of file diff --git a/src/widgets/mylar/widget.js b/src/widgets/mylar/widget.js new file mode 100644 index 000000000..031d43d6a --- /dev/null +++ b/src/widgets/mylar/widget.js @@ -0,0 +1,20 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api?cmd={endpoint}&apikey={key}", + proxyHandler: genericProxyHandler, + + mappings: { + issues: { + endpoint: "getIndex" + }, + series: { + endpoint: "seriesjsonListing" + }, + wanted: { + endpoint: "getWanted" + }, + }, +}; + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 7da77a0a6..4abed3dd8 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -21,6 +21,7 @@ import medusa from "./medusa/widget"; import miniflux from "./miniflux/widget"; import mikrotik from "./mikrotik/widget"; import moonraker from "./moonraker/widget"; +import mylar from "./mylar/widget"; import navidrome from "./navidrome/widget"; import nextdns from "./nextdns/widget"; import npm from "./npm/widget"; @@ -85,6 +86,7 @@ const widgets = { miniflux, mikrotik, moonraker, + mylar, navidrome, nextdns, npm,