mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 07:21:16 -07:00
Chore: full react hooks eslint compliance (#7040)
This commit is contained in:
@@ -3,11 +3,12 @@ import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next/pages";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import withWidgetFields from "utils/widget-fields";
|
||||
|
||||
const ROMM_DEFAULT_FIELDS = ["platforms", "totalRoms", "saves", "states"];
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
|
||||
export default function Component({ service }) {
|
||||
export default function Component({ service: configuredService }) {
|
||||
const service = withWidgetFields(configuredService, ROMM_DEFAULT_FIELDS);
|
||||
const { widget } = service;
|
||||
const { t } = useTranslation();
|
||||
const { data: response, error: responseError } = useWidgetAPI(widget, "statistics");
|
||||
@@ -16,12 +17,6 @@ export default function Component({ service }) {
|
||||
return <Container service={service} error={responseError} />;
|
||||
}
|
||||
|
||||
if (!widget.fields?.length > 0) {
|
||||
widget.fields = ROMM_DEFAULT_FIELDS;
|
||||
} else if (widget.fields.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("widgets/romm/component", () => {
|
||||
const service = { widget: { type: "romm" } };
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["platforms", "totalRoms", "saves", "states"]);
|
||||
expect(service.widget.fields).toBeUndefined();
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
||||
expect(screen.getByText("romm.platforms")).toBeInTheDocument();
|
||||
expect(screen.getByText("romm.totalRoms")).toBeInTheDocument();
|
||||
@@ -38,7 +38,7 @@ describe("widgets/romm/component", () => {
|
||||
const service = { widget: { type: "romm", fields: ["platforms", "totalRoms", "saves", "states", "screenshots"] } };
|
||||
renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["platforms", "totalRoms", "saves", "states"]);
|
||||
expect(service.widget.fields).toEqual(["platforms", "totalRoms", "saves", "states", "screenshots"]);
|
||||
});
|
||||
|
||||
it("renders values when loaded (and includes additional fields when explicitly selected)", () => {
|
||||
|
||||
Reference in New Issue
Block a user