Skip to content

Commit

Permalink
Merge branch 'develop' into issues/8321/Add_Next_and_Previous
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvesh-official authored Nov 28, 2024
2 parents 643b8ac + 6bea49a commit 63d4c9f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
5 changes: 3 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
files:
- source: /src/Locale/en/*.json
translation: /src/Locale/%two_letters_code%/%original_file_name%
- source: /public/locale/{{lang}}.json
translation: /public/locale/%two_letters_code%/%original_file_name%
bundles:
- 2

3 changes: 3 additions & 0 deletions src/Utils/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default async function request<TData, TBody>(
return result;
} catch (error: any) {
result = { error, res: undefined, data: undefined };
if (error.name === "AbortError") {
return result;
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Utils/request/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { mergeRequestOptions } from "@/Utils/request/utils";

export default function useMutation<TData, TBody>(
route: MutationRoute<TData, TBody>,
options: RequestOptions<TData>,
options: RequestOptions<TData, TBody>,
) {
const [response, setResponse] = React.useState<RequestResult<TData>>();
const [isProcessing, setIsProcessing] = React.useState(false);

const controllerRef = React.useRef<AbortController>();

const runQuery = React.useCallback(
async (overrides?: RequestOptions<TData>) => {
async (overrides?: RequestOptions<TData, TBody>) => {
controllerRef.current?.abort();

const controller = new AbortController();
Expand All @@ -31,8 +31,10 @@ export default function useMutation<TData, TBody>(

setIsProcessing(true);
const response = await request(route, { ...resolvedOptions, controller });
setResponse(response);
setIsProcessing(false);
if (response.error?.name !== "AbortError") {
setResponse(response);
setIsProcessing(false);
}
return response;
},
[route, JSON.stringify(options)],
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/request/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export default function useQuery<TData>(

setLoading(true);
const response = await request(route, { ...resolvedOptions, controller });
setResponse(response);
setLoading(false);
if (response.error?.name !== "AbortError") {
setResponse(response);
setLoading(false);
}
return response;
},
[route, JSON.stringify(options)],
Expand Down

0 comments on commit 63d4c9f

Please sign in to comment.