mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-27 06:21:18 -07:00
Chore: full react hooks eslint compliance (#7040)
This commit is contained in:
@@ -3,12 +3,13 @@ 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";
|
||||
|
||||
export const karakeepDefaultFields = ["bookmarks", "favorites", "archived", "highlights"];
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
|
||||
export default function Component({ service }) {
|
||||
export default function Component({ service: configuredService }) {
|
||||
const { t } = useTranslation();
|
||||
const service = withWidgetFields(configuredService, karakeepDefaultFields);
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
|
||||
@@ -17,12 +18,6 @@ export default function Component({ service }) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
|
||||
if (!widget.fields || widget.fields.length === 0) {
|
||||
widget.fields = karakeepDefaultFields;
|
||||
} else if (widget.fields?.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component, { karakeepDefaultFields } from "./component";
|
||||
import Component from "./component";
|
||||
|
||||
describe("widgets/karakeep/component", () => {
|
||||
beforeEach(() => {
|
||||
@@ -22,7 +22,7 @@ describe("widgets/karakeep/component", () => {
|
||||
const service = { widget: { type: "karakeep", url: "http://x" } };
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(karakeepDefaultFields);
|
||||
expect(service.widget.fields).toBeUndefined();
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
||||
expect(screen.getByText("karakeep.bookmarks")).toBeInTheDocument();
|
||||
expect(screen.getByText("karakeep.favorites")).toBeInTheDocument();
|
||||
@@ -38,7 +38,7 @@ describe("widgets/karakeep/component", () => {
|
||||
const service = { widget: { type: "karakeep", fields: ["tags", "lists", "bookmarks", "favorites", "archived"] } };
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["tags", "lists", "bookmarks", "favorites"]);
|
||||
expect(service.widget.fields).toEqual(["tags", "lists", "bookmarks", "favorites", "archived"]);
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
||||
expect(screen.getByText("karakeep.tags")).toBeInTheDocument();
|
||||
expect(screen.getByText("karakeep.lists")).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user