From efc4211a29d25068f408d34138be3c98ac6a9b5b Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Sun, 8 Sep 2024 14:11:57 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(signals):=20remov?= =?UTF-8?q?e=20all=20signals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/pagination-table/useFEPagination.ts | 8 ++------ src/frontend/lib/data/makeRequest.ts | 11 +++-------- src/frontend/lib/data/useApi/index.ts | 3 +-- src/frontend/lib/data/useApi/useApiQueries.ts | 6 ++---- src/frontend/lib/data/useApi/usePaginatedData.ts | 3 +-- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/frontend/components/app/pagination-table/useFEPagination.ts b/src/frontend/components/app/pagination-table/useFEPagination.ts index daa84ed5..4cfd5094 100644 --- a/src/frontend/components/app/pagination-table/useFEPagination.ts +++ b/src/frontend/components/app/pagination-table/useFEPagination.ts @@ -22,12 +22,8 @@ export function useFEPagination( ): UseQueryResult> { return useQuery>({ queryKey: getQueryCachekey(endPoint), - queryFn: async ({ signal }) => { - return await ApiRequest.GET( - endPoint, - signal, - "Data could not be retrieved" - ); + queryFn: async () => { + return await ApiRequest.GET(endPoint, "Data could not be retrieved"); }, select: (data: any) => { let returnData: T[] = data as unknown as T[]; diff --git a/src/frontend/lib/data/makeRequest.ts b/src/frontend/lib/data/makeRequest.ts index 9f214930..fe2e96be 100644 --- a/src/frontend/lib/data/makeRequest.ts +++ b/src/frontend/lib/data/makeRequest.ts @@ -38,17 +38,12 @@ const handleRequestError = async (response: Response, errorMessage: string) => { throw new ApiRequestError(response.status, error.message || errorMessage); }; -export async function makeRawRequest( - path: string, - signal?: AbortSignal, - errorMessage?: string -) { +export async function makeRawRequest(path: string, errorMessage?: string) { const response = await fetch(pathWithBaseUrl(path), { method: "GET", headers: { ...getRequestHeaders(), }, - signal, }); await handleRequestError( @@ -91,8 +86,8 @@ const makeActionRequest = async ( }; export const ApiRequest = { - GET: async (path: string, signal: AbortSignal, errorMessage?: string) => { - const response = await makeRawRequest(path, signal, errorMessage); + GET: async (path: string, errorMessage?: string) => { + const response = await makeRawRequest(path, errorMessage); return response.json(); }, POST: (path: string, data: unknown) => makeActionRequest("POST", path, data), diff --git a/src/frontend/lib/data/useApi/index.ts b/src/frontend/lib/data/useApi/index.ts index 8c507bd0..4bd91073 100644 --- a/src/frontend/lib/data/useApi/index.ts +++ b/src/frontend/lib/data/useApi/index.ts @@ -16,7 +16,7 @@ export function useApi(endPoint: string, options: IUseApiOptions) { const { data = options.defaultData, ...rest } = useQuery({ enabled: router.isReady && builtOptions.enabled, queryKey: getQueryCachekey(endPoint), - queryFn: async ({ signal }) => { + queryFn: async () => { try { if (options.request) { return await ApiRequest.ACTION( @@ -32,7 +32,6 @@ export function useApi(endPoint: string, options: IUseApiOptions) { } return await ApiRequest.GET( endPoint, - signal, options.errorMessage ? _(options.errorMessage) : undefined ); } catch (error) { diff --git a/src/frontend/lib/data/useApi/useApiQueries.ts b/src/frontend/lib/data/useApi/useApiQueries.ts index e7b2a17d..aec689c6 100644 --- a/src/frontend/lib/data/useApi/useApiQueries.ts +++ b/src/frontend/lib/data/useApi/useApiQueries.ts @@ -32,10 +32,8 @@ export function useApiQueries({ meta: { persist, }, - queryFn: async ({ signal }) => - dataTransformer( - await ApiRequest.GET(pathFn(inputItem[accessor]), signal) - ) as P, + queryFn: async () => + dataTransformer(await ApiRequest.GET(pathFn(inputItem[accessor]))) as P, })), }); diff --git a/src/frontend/lib/data/useApi/usePaginatedData.ts b/src/frontend/lib/data/useApi/usePaginatedData.ts index 231330ff..ab7dcb79 100644 --- a/src/frontend/lib/data/useApi/usePaginatedData.ts +++ b/src/frontend/lib/data/useApi/usePaginatedData.ts @@ -20,10 +20,9 @@ export function usePaginatedData>( return useQuery>({ queryKey: getPaginatedDataCachekey(endPoint, dataState), - queryFn: async ({ signal }) => { + queryFn: async () => { return await ApiRequest.GET( endPoint + tableDataParamsToQueryString(dataState), - signal, "Data could not be retrieved" ); },