From 266cfe7a933956add7a4446361e6ce4ad40972ac Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Sun, 31 Dec 2023 16:20:30 +0000 Subject: [PATCH 1/2] 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, From b36147be7280359863e8e8a5499acb5b173d79c7 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Sun, 31 Dec 2023 16:24:29 +0000 Subject: [PATCH 2/2] pass linting --- src/widgets/romm/component.jsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/widgets/romm/component.jsx b/src/widgets/romm/component.jsx index 393d9e68..c84669d1 100644 --- a/src/widgets/romm/component.jsx +++ b/src/widgets/romm/component.jsx @@ -1,31 +1,27 @@ -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"); + const { data: response, error: responseError } = useWidgetAPI(widget, "statistics"); - if (statisticsStatsError) { + if (responseError) { return ( - + ); } - if (statisticsStatsError) { - return ; + if (responseError) { + return ; } - if (statistics) { - const platforms = statistics.filter(x => x.n_roms!=0).length - const totalRoms = statistics.reduce((total, stat) => total + stat.n_roms, 0); + if (response) { + const platforms = response.filter(x => x.n_roms!==0).length + const totalRoms = response.reduce((total, stat) => total + stat.n_roms, 0); return (