From 266cfe7a933956add7a4446361e6ce4ad40972ac Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Sun, 31 Dec 2023 16:20:30 +0000 Subject: [PATCH] working romm widget --- public/locales/en/common.json | 4 ++++ src/widgets/components.js | 1 + src/widgets/romm/component.jsx | 36 ++++++++++++++++++++++++++++++++++ src/widgets/romm/widget.js | 14 +++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 57 insertions(+) create mode 100644 src/widgets/romm/component.jsx create mode 100644 src/widgets/romm/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 7e6ea3e9..eb314ff1 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -809,5 +809,9 @@ "totalTemplates": "Total Templates", "totalSyncs": "Total Syncs", "loadedCards": "Loaded Cards" + }, + "romm": { + "platforms": "Platforms", + "totalRoms": "Total ROMs" } } \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 9bbb60de..03f17bde 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -87,6 +87,7 @@ const components = { qnap: dynamic(() => import("./qnap/component")), radarr: dynamic(() => import("./radarr/component")), readarr: dynamic(() => import("./readarr/component")), + romm: dynamic(() => import("./romm/component")), rutorrent: dynamic(() => import("./rutorrent/component")), sabnzbd: dynamic(() => import("./sabnzbd/component")), scrutiny: dynamic(() => import("./scrutiny/component")), diff --git a/src/widgets/romm/component.jsx b/src/widgets/romm/component.jsx new file mode 100644 index 00000000..393d9e68 --- /dev/null +++ b/src/widgets/romm/component.jsx @@ -0,0 +1,36 @@ +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: statistics, error: statisticsStatsError } = useWidgetAPI(widget, "statistics"); + + if (statisticsStatsError) { + return ( + + + + ); + } + + if (statisticsStatsError) { + return ; + } + + if (statistics) { + const platforms = statistics.filter(x => x.n_roms!=0).length + const totalRoms = statistics.reduce((total, stat) => total + stat.n_roms, 0); + return ( + + + + + ); + } +} \ No newline at end of file diff --git a/src/widgets/romm/widget.js b/src/widgets/romm/widget.js new file mode 100644 index 00000000..ee80f9bc --- /dev/null +++ b/src/widgets/romm/widget.js @@ -0,0 +1,14 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + statistics: { + endpoint: "platforms", + } + }, +}; + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 1f6e88d5..c79d695b 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -79,6 +79,7 @@ import qbittorrent from "./qbittorrent/widget"; import qnap from "./qnap/widget"; import radarr from "./radarr/widget"; import readarr from "./readarr/widget"; +import romm from "./romm/widget"; import rutorrent from "./rutorrent/widget"; import sabnzbd from "./sabnzbd/widget"; import scrutiny from "./scrutiny/widget"; @@ -188,6 +189,7 @@ const widgets = { qnap, radarr, readarr, + romm, rutorrent, sabnzbd, scrutiny,