From 338aa17fe8525c006ab222ec02c910c01351d391 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Mon, 11 Nov 2024 01:54:01 +0200 Subject: [PATCH] Refactor SWR imports: consolidate fetcher and mutationFetcher into units/swr, update component imports accordingly --- .../features/about/releaseNotes/ReleaseNotesContainer.tsx | 3 +-- .../src/features/about/system/SystemVersionContainer.tsx | 3 +-- .../features/settings/system/CacheSettingsContainer.tsx | 4 +--- frontend/src/providers/UserPermissionsProvider.tsx | 3 +-- frontend/src/{utils/swr.ts => units/swr/fetchers.ts} | 0 frontend/src/units/swr/index.ts | 8 ++++++++ 6 files changed, 12 insertions(+), 9 deletions(-) rename frontend/src/{utils/swr.ts => units/swr/fetchers.ts} (100%) create mode 100644 frontend/src/units/swr/index.ts diff --git a/frontend/src/features/about/releaseNotes/ReleaseNotesContainer.tsx b/frontend/src/features/about/releaseNotes/ReleaseNotesContainer.tsx index 2669bc9..28d837b 100644 --- a/frontend/src/features/about/releaseNotes/ReleaseNotesContainer.tsx +++ b/frontend/src/features/about/releaseNotes/ReleaseNotesContainer.tsx @@ -2,8 +2,7 @@ import React from "react"; import ReleaseNotesList from "./ReleaseNotesList"; import TimelineComponent from "../timeline/TimelineComponent"; import { endpoints } from "../../../utils/api"; -import useSWR from "swr"; -import { fetcher } from "utils/swr"; +import { useSWR, fetcher } from "units/swr"; import { blip } from "utils"; import { dtos } from "types"; diff --git a/frontend/src/features/about/system/SystemVersionContainer.tsx b/frontend/src/features/about/system/SystemVersionContainer.tsx index 8c3204c..95cde2d 100644 --- a/frontend/src/features/about/system/SystemVersionContainer.tsx +++ b/frontend/src/features/about/system/SystemVersionContainer.tsx @@ -1,8 +1,7 @@ import React from "react"; import SystemVersionComponent from "./SystemVersionComponent"; import { endpoints } from "../../../utils/api"; -import useSWR from "swr"; -import { fetcher } from "utils/swr"; +import { useSWR, fetcher } from "units/swr"; import { blip } from "utils"; import { dtos } from "types"; diff --git a/frontend/src/features/settings/system/CacheSettingsContainer.tsx b/frontend/src/features/settings/system/CacheSettingsContainer.tsx index dd7140f..a423589 100644 --- a/frontend/src/features/settings/system/CacheSettingsContainer.tsx +++ b/frontend/src/features/settings/system/CacheSettingsContainer.tsx @@ -3,9 +3,7 @@ import CacheSettingsComponent from "./CacheSettingsComponent"; import { useTranslation } from "react-i18next"; import { endpoints } from "utils/api"; import { blip } from "utils"; -import useSWRMutation from "swr/mutation"; -import { Key } from "swr"; -import { mutationFetcher } from "utils/swr"; +import { useSWRMutation, mutationFetcher, Key } from "units/swr"; const CacheSettingsContainer: React.FC = () => { const { t } = useTranslation(); diff --git a/frontend/src/providers/UserPermissionsProvider.tsx b/frontend/src/providers/UserPermissionsProvider.tsx index 7125935..6d80d41 100644 --- a/frontend/src/providers/UserPermissionsProvider.tsx +++ b/frontend/src/providers/UserPermissionsProvider.tsx @@ -1,8 +1,7 @@ import React, { useState, useContext, useMemo, ReactNode } from "react"; import { endpoints } from "../utils/api"; import { PermissionsDto } from "types/dtos"; -import useSWR from "swr"; -import { fetcher } from "utils/swr"; +import { useSWR, fetcher } from "units/swr"; import { blip } from "utils"; const permissionCodes = { diff --git a/frontend/src/utils/swr.ts b/frontend/src/units/swr/fetchers.ts similarity index 100% rename from frontend/src/utils/swr.ts rename to frontend/src/units/swr/fetchers.ts diff --git a/frontend/src/units/swr/index.ts b/frontend/src/units/swr/index.ts new file mode 100644 index 0000000..80fe9fd --- /dev/null +++ b/frontend/src/units/swr/index.ts @@ -0,0 +1,8 @@ +import useSWR from "swr"; +import type { Key } from "swr"; +import useSWRMutation from "swr/mutation"; + +export * from "./fetchers"; + +export { useSWR, useSWRMutation }; +export type { Key };