Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hum 50 #2667

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Hum 50 #2667

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/apps/human-app/frontend/src/api/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,20 @@ export function createFetcher(defaultFetcherConfig?: {
}) {
async function fetcher<SuccessInput, SuccessOutput>(
url: string | URL,
fetcherOptions: FetcherOptionsWithValidation<SuccessInput, SuccessOutput>
fetcherOptions: FetcherOptionsWithValidation<SuccessInput, SuccessOutput>,
abortSignal?: AbortSignal
): Promise<SuccessOutput>;

async function fetcher(
url: FetcherUrl,
fetcherOptions: FetcherOptionsWithoutValidation
fetcherOptions: FetcherOptionsWithoutValidation,
abortSignal?: AbortSignal
): Promise<unknown>;

async function fetcher<SuccessInput, SuccessOutput>(
url: FetcherUrl,
fetcherOptions: FetcherOptions<SuccessInput, SuccessOutput>
fetcherOptions: FetcherOptions<SuccessInput, SuccessOutput>,
abortSignal?: AbortSignal
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- required unknown for correct type intellisense
): Promise<SuccessOutput | unknown> {
let fetcherOptionsWithDefaults = defaultFetcherConfig?.options
Expand All @@ -99,10 +102,18 @@ export function createFetcher(defaultFetcherConfig?: {
: fetcherOptions.options;
if (fetcherOptions.authenticated) {
fetcherOptionsWithDefaults = appendHeader(fetcherOptionsWithDefaults, {
Authorization: `Bearer ${browserAuthProvider.getAccessToken() ?? ''}`,
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if we change the rule globally in order to allow not only strings, but also booleans, numbers and null/undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KacperKoza343 could you please do it in this PR?

Authorization: `Bearer ${browserAuthProvider.getAccessToken()}`,
});
}

if (abortSignal) {
fetcherOptionsWithDefaults = {
...fetcherOptionsWithDefaults,
signal: abortSignal,
};
}

const baseUrl = (() => {
const currentUrl = fetcherOptions.baseUrl
? () => fetcherOptions.baseUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ type GetJobTableDataDto = JobsFilterStoreProps['filterParams'] & {
oracle_address: string;
};

const getAvailableJobsTableData = async (dto: GetJobTableDataDto) => {
const getAvailableJobsTableData = async (
dto: GetJobTableDataDto,
abortSignal: AbortSignal
) => {
return apiClient(
`${apiPaths.worker.jobs.path}?${stringifyUrlQueryObject({ ...dto })}`,
{
Expand All @@ -40,7 +43,8 @@ const getAvailableJobsTableData = async (dto: GetJobTableDataDto) => {
options: {
method: 'GET',
},
}
},
abortSignal
);
};

Expand All @@ -51,7 +55,7 @@ export function useGetAvailableJobsData() {

return useQuery({
queryKey: ['availableJobs', dto],
queryFn: () => getAvailableJobsTableData(dto),
queryFn: ({ signal }) => getAvailableJobsTableData(dto, signal),
});
}

Expand All @@ -63,7 +67,7 @@ export function useInfiniteGetAvailableJobsData() {
return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['availableJobsInfinite', dto],
queryFn: () => getAvailableJobsTableData(dto),
queryFn: ({ signal }) => getAvailableJobsTableData(dto, signal),
getNextPageParam: (pageParams) => {
return pageParams.total_pages - 1 <= pageParams.page
? undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ type GetMyJobTableDataDto = MyJobsFilterStoreProps['filterParams'] & {
oracle_address: string;
};

const getMyJobsTableData = async (dto: GetMyJobTableDataDto) => {
const getMyJobsTableData = async (
dto: GetMyJobTableDataDto,
abortSignal: AbortSignal
) => {
return apiClient(
`${apiPaths.worker.myJobs.path}?${stringifyUrlQueryObject({ ...dto })}`,
{
Expand All @@ -44,7 +47,8 @@ const getMyJobsTableData = async (dto: GetMyJobTableDataDto) => {
options: {
method: 'GET',
},
}
},
abortSignal
);
};

Expand All @@ -54,7 +58,7 @@ export function useGetMyJobsData() {
const dto = { ...filterParams, oracle_address: address ?? '' };
return useQuery({
queryKey: ['myJobs', dto],
queryFn: () => getMyJobsTableData(dto),
queryFn: ({ signal }) => getMyJobsTableData(dto, signal),
});
}

Expand All @@ -66,7 +70,7 @@ export function useInfiniteGetMyJobsData() {
return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['myJobsInfinite', dto],
queryFn: () => getMyJobsTableData(dto),
queryFn: ({ signal }) => getMyJobsTableData(dto, signal),
getNextPageParam: (pageParams) => {
return pageParams.total_pages - 1 <= pageParams.page
? undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const H_CAPTCHA_ORACLE: OracleSuccessResponse = {

export async function getOracles({
selected_job_types,
signal,
}: {
selected_job_types: string[];
signal: AbortSignal;
}) {
let oracles = [H_CAPTCHA_ORACLE];
const queryParams = selected_job_types.length
Expand All @@ -44,7 +46,8 @@ export async function getOracles({
{
successSchema: OraclesSuccessSchema,
options: { method: 'GET' },
}
},
signal
);

oracles = oracles.concat(result);
Expand All @@ -55,7 +58,7 @@ export async function getOracles({
export function useGetOracles() {
const { selected_job_types } = useJobsTypesOraclesFilter();
return useQuery({
queryFn: () => getOracles({ selected_job_types }),
queryFn: ({ signal }) => getOracles({ selected_job_types, signal }),
queryKey: ['oracles', selected_job_types],
});
}