@ventlio/tanstack-query 0.2.75 → 0.2.76

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.
package/dist/index.mjs CHANGED
@@ -459,23 +459,23 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
459
459
  res(null);
460
460
  }
461
461
  };
462
- const query = useInfiniteQuery([path, {}], ({ pageParam = path }) => new Promise((res, rej) => sendRequest(res, rej, pageParam)), {
463
- enabled: load,
464
- getNextPageParam: (lastPage, pages) => constructPaginationLink('next_page', lastPage, pages),
465
- getPreviousPageParam: (lastPage, pages) => constructPaginationLink('previous_page', lastPage, pages),
466
- ...queryOptions,
467
- });
468
462
  /**
469
463
  *
470
464
  * This pagination implementation is currently tied to our use case
471
465
  */
472
- const constructPaginationLink = (direction, lastPage, pages) => {
473
- const [pathname, queryString] = lastPage.split('?');
466
+ const constructPaginationLink = (direction, lastPage) => {
467
+ const [pathname, queryString] = path.split('?');
474
468
  const queryParams = new URLSearchParams(queryString);
475
- const lastPageItem = pages[pages.length - 1];
476
- queryParams.set('page', String(lastPageItem?.data.pagination[direction]));
469
+ const lastPageItem = lastPage.data.pagination[direction];
470
+ queryParams.set('page', String(lastPageItem));
477
471
  return pathname + '?' + queryParams.toString();
478
472
  };
473
+ const query = useInfiniteQuery([path, {}], ({ pageParam = path }) => new Promise((res, rej) => sendRequest(res, rej, pageParam)), {
474
+ enabled: load,
475
+ getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
476
+ getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
477
+ ...queryOptions,
478
+ });
479
479
  useEffect(() => {
480
480
  if (keyTracker) {
481
481
  // set expiration time for the tracker
@@ -34,23 +34,23 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
34
34
  res(null);
35
35
  }
36
36
  };
37
- const query = useInfiniteQuery([path, {}], ({ pageParam = path }) => new Promise((res, rej) => sendRequest(res, rej, pageParam)), {
38
- enabled: load,
39
- getNextPageParam: (lastPage, pages) => constructPaginationLink('next_page', lastPage, pages),
40
- getPreviousPageParam: (lastPage, pages) => constructPaginationLink('previous_page', lastPage, pages),
41
- ...queryOptions,
42
- });
43
37
  /**
44
38
  *
45
39
  * This pagination implementation is currently tied to our use case
46
40
  */
47
- const constructPaginationLink = (direction, lastPage, pages) => {
48
- const [pathname, queryString] = lastPage.split('?');
41
+ const constructPaginationLink = (direction, lastPage) => {
42
+ const [pathname, queryString] = path.split('?');
49
43
  const queryParams = new URLSearchParams(queryString);
50
- const lastPageItem = pages[pages.length - 1];
51
- queryParams.set('page', String(lastPageItem?.data.pagination[direction]));
44
+ const lastPageItem = lastPage.data.pagination[direction];
45
+ queryParams.set('page', String(lastPageItem));
52
46
  return pathname + '?' + queryParams.toString();
53
47
  };
48
+ const query = useInfiniteQuery([path, {}], ({ pageParam = path }) => new Promise((res, rej) => sendRequest(res, rej, pageParam)), {
49
+ enabled: load,
50
+ getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
51
+ getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
52
+ ...queryOptions,
53
+ });
54
54
  useEffect(() => {
55
55
  if (keyTracker) {
56
56
  // set expiration time for the tracker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ventlio/tanstack-query",
3
- "version": "0.2.75",
3
+ "version": "0.2.76",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -68,43 +68,42 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
68
68
  }
69
69
  };
70
70
 
71
- const query = useInfiniteQuery<any, any, IRequestSuccess<TResponse & { pagination: Pagination }>>(
72
- [path, {}],
73
- ({ pageParam = path }) =>
74
- new Promise<IRequestSuccess<TResponse & { pagination: Pagination }> | IRequestError>((res, rej) =>
75
- sendRequest(res, rej, pageParam)
76
- ),
77
- {
78
- enabled: load,
79
- getNextPageParam: (lastPage, pages) => constructPaginationLink('next_page', lastPage, pages),
80
- getPreviousPageParam: (lastPage, pages) => constructPaginationLink('previous_page', lastPage, pages),
81
- ...(queryOptions as any),
82
- }
83
- );
84
-
85
71
  /**
86
72
  *
87
73
  * This pagination implementation is currently tied to our use case
88
74
  */
89
75
  const constructPaginationLink = (
90
76
  direction: 'next_page' | 'previous_page',
91
- lastPage: string,
92
- pages: IRequestSuccess<
77
+ lastPage: IRequestSuccess<
93
78
  TResponse & {
94
79
  pagination: Pagination;
95
80
  }
96
- >[]
81
+ >
97
82
  ) => {
98
- const [pathname, queryString] = lastPage.split('?');
83
+ const [pathname, queryString] = path.split('?');
99
84
 
100
85
  const queryParams = new URLSearchParams(queryString);
101
- const lastPageItem = pages[pages.length - 1];
86
+ const lastPageItem = lastPage.data.pagination[direction];
102
87
 
103
- queryParams.set('page', String(lastPageItem?.data.pagination[direction]));
88
+ queryParams.set('page', String(lastPageItem));
104
89
 
105
90
  return pathname + '?' + queryParams.toString();
106
91
  };
107
92
 
93
+ const query = useInfiniteQuery<any, any, IRequestSuccess<TResponse & { pagination: Pagination }>>(
94
+ [path, {}],
95
+ ({ pageParam = path }) =>
96
+ new Promise<IRequestSuccess<TResponse & { pagination: Pagination }> | IRequestError>((res, rej) =>
97
+ sendRequest(res, rej, pageParam)
98
+ ),
99
+ {
100
+ enabled: load,
101
+ getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
102
+ getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
103
+ ...(queryOptions as any),
104
+ }
105
+ );
106
+
108
107
  useEffect(() => {
109
108
  if (keyTracker) {
110
109
  // set expiration time for the tracker