Skip to content

Commit

Permalink
♻️ refactor(signals): remove all signals
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Sep 8, 2024
1 parent 7cb7719 commit efc4211
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ export function useFEPagination<T>(
): UseQueryResult<PaginatedData<T>> {
return useQuery<PaginatedData<T>>({
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[];
Expand Down
11 changes: 3 additions & 8 deletions src/frontend/lib/data/makeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/lib/data/useApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useApi<T>(endPoint: string, options: IUseApiOptions<T>) {
const { data = options.defaultData, ...rest } = useQuery<T>({
enabled: router.isReady && builtOptions.enabled,
queryKey: getQueryCachekey(endPoint),
queryFn: async ({ signal }) => {
queryFn: async () => {
try {
if (options.request) {
return await ApiRequest.ACTION(
Expand All @@ -32,7 +32,6 @@ export function useApi<T>(endPoint: string, options: IUseApiOptions<T>) {
}
return await ApiRequest.GET(
endPoint,
signal,
options.errorMessage ? _(options.errorMessage) : undefined
);
} catch (error) {
Expand Down
6 changes: 2 additions & 4 deletions src/frontend/lib/data/useApi/useApiQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export function useApiQueries<T, P>({
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,
})),
});

Expand Down
3 changes: 1 addition & 2 deletions src/frontend/lib/data/useApi/usePaginatedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ export function usePaginatedData<T extends Record<string, unknown>>(

return useQuery<PaginatedData<T>>({
queryKey: getPaginatedDataCachekey(endPoint, dataState),
queryFn: async ({ signal }) => {
queryFn: async () => {
return await ApiRequest.GET(
endPoint + tableDataParamsToQueryString(dataState),
signal,
"Data could not be retrieved"
);
},
Expand Down

0 comments on commit efc4211

Please sign in to comment.