@go-avro/avro-js 0.0.2-beta.120 → 0.0.2-beta.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,7 +21,7 @@ declare module '../client/QueryClient' {
|
|
|
21
21
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
22
22
|
sleep(ms: number): Promise<void>;
|
|
23
23
|
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
24
|
-
useGetJobs(
|
|
24
|
+
useGetJobs(onProgress?: (fraction: number) => void): UseQueryResult<Job[], StandardError>;
|
|
25
25
|
getJobsFromCache(): Job[];
|
|
26
26
|
useGetInfiniteJobs(body: {
|
|
27
27
|
amt?: number;
|
|
@@ -282,6 +282,7 @@ export declare class AvroQueryClient {
|
|
|
282
282
|
readonly socket: Socket;
|
|
283
283
|
_isAuthenticated: boolean;
|
|
284
284
|
companyId: string | null;
|
|
285
|
+
company: Company | null;
|
|
285
286
|
constructor(config: AvroQueryClientConfig);
|
|
286
287
|
emit(eventName: string, data: unknown): void;
|
|
287
288
|
on<T>(eventName: string, callback: (data: T) => void): void;
|
|
@@ -27,7 +27,8 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
|
27
27
|
throw new Error("No company ID set and no companies available");
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
this.company = await this.get(`/company/${this.companyId}`);
|
|
31
|
+
return this.company;
|
|
31
32
|
},
|
|
32
33
|
});
|
|
33
34
|
};
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
-
AvroQueryClient.prototype.getJobsFromCache = function (
|
|
3
|
+
AvroQueryClient.prototype.getJobsFromCache = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
5
|
-
|
|
6
|
-
if (cachedJobsData && cachedJobsData.pages) {
|
|
7
|
-
return cachedJobsData.pages.flat();
|
|
8
|
-
}
|
|
9
|
-
const cachedJobs = queryClient.getQueryData(['jobs', this.companyId]);
|
|
10
|
-
return cachedJobs || [];
|
|
5
|
+
return (queryClient.getQueryData(['jobs', this.companyId, this.company?.num_jobs]) ?? []);
|
|
11
6
|
};
|
|
12
|
-
AvroQueryClient.prototype.useGetJobs = function (
|
|
7
|
+
AvroQueryClient.prototype.useGetJobs = function (onProgress) {
|
|
13
8
|
const queryClient = this.getQueryClient();
|
|
14
9
|
const amt = 50;
|
|
15
10
|
return useQuery({
|
|
16
|
-
queryKey: ['jobs', this.companyId,
|
|
11
|
+
queryKey: ['jobs', this.companyId, this.company?.num_jobs],
|
|
17
12
|
queryFn: async () => {
|
|
18
|
-
if (
|
|
13
|
+
if (this.company?.num_jobs === 0) {
|
|
19
14
|
onProgress?.(1);
|
|
20
15
|
return [];
|
|
21
16
|
}
|
|
22
17
|
onProgress?.(0);
|
|
23
|
-
const pageCount = amt ? Math.ceil(
|
|
18
|
+
const pageCount = amt ? Math.ceil((this.company?.num_jobs ?? 0) / amt) : 0;
|
|
24
19
|
let completed = 0;
|
|
25
20
|
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * amt }));
|
|
26
21
|
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
@@ -50,7 +45,7 @@ AvroQueryClient.prototype.useGetJobs = function (total = 0, onProgress) {
|
|
|
50
45
|
AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
51
46
|
const queryClient = this.getQueryClient();
|
|
52
47
|
const result = useInfiniteQuery({
|
|
53
|
-
queryKey: ['jobs', this.companyId, body.amt ?? 50, body.query ?? "", body.routeId ?? ""],
|
|
48
|
+
queryKey: ['infinite', 'jobs', this.companyId, body.amt ?? 50, body.query ?? "", body.routeId ?? ""],
|
|
54
49
|
initialPageParam: 0,
|
|
55
50
|
getNextPageParam: (lastPage, allPages) => {
|
|
56
51
|
if (lastPage.length < (body.amt ?? 50))
|