From ac86a08a53af299821ac5d45dff2cf7decb086b9 Mon Sep 17 00:00:00 2001 From: InsertDisc <31751462+InsertDisc@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:59:42 -0400 Subject: [PATCH] Update component.jsx Add field limiting logic. Cleaned up response error that is returned. Refactor size returned to use 'common.bytes' to avoid predefined calculations. --- src/widgets/romm/component.jsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/widgets/romm/component.jsx b/src/widgets/romm/component.jsx index 94be30d1d..9f095cbec 100644 --- a/src/widgets/romm/component.jsx +++ b/src/widgets/romm/component.jsx @@ -4,20 +4,26 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +export const rommDefaultFields = ["platforms", "roms", "saves", "states"]; + export default function Component({ service }) { const { widget } = service; const { t } = useTranslation(); - const { data: response, error: responseError } = useWidgetAPI(widget, "statistics"); if (responseError) { - return ( - - - - ); + return ; } + // Default fields + if (!widget.fields?.length > 0) { + widget.fields = rommDefaultFields; + } + const MAX_ALLOWED_FIELDS = 4; + if (widget.fields?.length > MAX_ALLOWED_FIELDS) { + widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS); + } + if (!response) { return ( @@ -32,8 +38,6 @@ export default function Component({ service }) { } if (response) { - const totalFilesizeGB = (response.FILESIZE / 1024 ** 3).toFixed(2); - return ( @@ -41,7 +45,7 @@ export default function Component({ service }) { - + ); }