Compare commits

...

2 Commits

Author SHA1 Message Date
Hein
1f5999b2d1 RELEASING: Releasing 1 package(s)
Releases:
  @warkypublic/oranguru@0.0.8

[skip ci]
2025-10-23 15:58:07 +02:00
Hein
cdcb5c2684 docs(changeset): Fixed memo of options in GridlerAPIAdaptor 2025-10-23 15:58:04 +02:00
3 changed files with 125 additions and 99 deletions

View File

@ -1,5 +1,11 @@
# @warkypublic/zustandsyncstore
## 0.0.8
### Patch Changes
- cdcb5c2: Fixed memo of options in GridlerAPIAdaptor
## 0.0.7
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"name": "@warkypublic/oranguru",
"author": "Warky Devs",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useEffect } from 'react';
import React, { useCallback, useEffect } from 'react';
import type { APIOptions } from '../../utils/types';
@ -20,7 +20,8 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
s.mounted,
]);
const useAPIQuery: (index: number) => Promise<any> = async (index: number) => {
const useAPIQuery: (index: number) => Promise<any> = useCallback(
async (index: number) => {
const colSort = getState('colSort');
const pageSize = getState('pageSize');
const colFilters = getState('colFilters');
@ -67,14 +68,21 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
r.controller?.abort?.();
}
});
if (_active_requests && currentRequestIndex >= 0 && _active_requests[currentRequestIndex]) {
if (
_active_requests &&
currentRequestIndex >= 0 &&
_active_requests[currentRequestIndex]
) {
//console.log(`Already queued ${index}`, index, s._active_requests);
setState('loadingData', false);
return undefined;
}
const controller = new AbortController();
await setStateFN('_active_requests', (cv) => [...(cv ?? []), { controller, page: index }]);
await setStateFN('_active_requests', (cv) => [
...(cv ?? []),
{ controller, page: index },
]);
const res = await fetch(
`${props.url}?x-limit=${String(pageSize ?? 50)}&x-offset=${String((pageSize ?? 50) * index)}`,
@ -107,9 +115,12 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
}
setState('loadingData', false);
return [];
};
},
[getState, props.authtoken, props.url, props.options, setState, setStateFN, addError]
);
const askAPIRowNumber: (key: string) => Promise<number> = async (key: string) => {
const askAPIRowNumber: (key: string) => Promise<number> = useCallback(
async (key: string) => {
const colFilters = getState('colFilters');
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
@ -130,6 +141,13 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
});
}
if (props.options && props.options.length > 0) {
const optionHeaders = GoAPIHeaders(props.options);
for (const oh in optionHeaders) {
head.set(oh, optionHeaders[oh]);
}
}
const controller = new AbortController();
const res = await fetch(`${props.url}?x-fetch-rownumber=${key}}`, {
@ -146,12 +164,14 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
addError(`${res.status} ${res.statusText}`, 'api', props.url);
}
return [];
};
},
[props.url, props.authtoken, props.options, getState, addError]
);
useEffect(() => {
setState('useAPIQuery', useAPIQuery);
setState('askAPIRowNumber', askAPIRowNumber);
}, [props.url, props.authtoken, mounted, setState]);
}, [props.url, props.authtoken, props.options, mounted, setState]);
return <></>;
}