diff --git a/src/widgets/suwayomi/component.jsx b/src/widgets/suwayomi/component.jsx index e9965b924..acd57b5fd 100644 --- a/src/widgets/suwayomi/component.jsx +++ b/src/widgets/suwayomi/component.jsx @@ -4,10 +4,27 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +/** + * @param {string[]|null} Fields + * @returns {string[]} + */ +function makeFields(Fields = []) { + let fields = Fields ?? []; + if (fields.length === 0) { + fields = ["download", "nondownload", "read", "unread"]; + } + if (fields.length > 4) { + fields.length = 4; + } + fields = fields.map((f) => f.toLowerCase()); + + return fields; +} + export default function Component({ service }) { const { t } = useTranslation(); - /** @type {{widget: { fields: string[] }}} */ + /** @type {{widget: { fields: string[]|null }}} */ const { widget } = service; /** @type { { data: { label: string, count: number }[], error: unk }} */ @@ -18,9 +35,7 @@ export default function Component({ service }) { } if (!suwayomiData) { - if (widget.fields.length > 4) { - widget.fields.length = 4; - } + widget.fields = makeFields(widget.fields); return ( {widget.fields.map((Field) => { diff --git a/src/widgets/suwayomi/proxy.js b/src/widgets/suwayomi/proxy.js index 2d25438d8..67263c3f7 100644 --- a/src/widgets/suwayomi/proxy.js +++ b/src/widgets/suwayomi/proxy.js @@ -173,11 +173,11 @@ function extractCounts(responseJSON, fields) { } /** - * @param {string[]} Fields + * @param {string[]|null} Fields * @returns {string[]} */ -function makeFields(Fields) { - let fields = Fields; +function makeFields(Fields = []) { + let fields = Fields ?? []; if (fields.length === 0) { fields = ["download", "nondownload", "read", "unread"]; } @@ -193,7 +193,7 @@ function makeFields(Fields) { * @typedef {object} widget * @property {string} username * @property {string} password - * @property {string[]} fields + * @property {string[]|null} fields * @property {string|number|undefined} category * @property {keyof typeof widgets} type */