PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/Views/Components/ListTable/api.ts +14 -2 2.30.04.16.9 View file →
@@ -7,9 +7,9 @@
7 7 private controller: AbortController | null;
8 8 private readonly headers: {'X-WP-Nonce': string; 'Content-Type': string};
9 9 private readonly swrOptions;
10 10
11 - constructor({apiNonce, apiRoot, preload = null}) {
11 + constructor({apiNonce, apiRoot, preload = null, swrConfig = {}}) {
12 12 this.controller = null;
13 13 this.apiRoot = apiRoot;
14 14 this.headers = {
15 15 'Content-Type': 'application/json',
@@ -16,8 +16,9 @@
16 16 'X-WP-Nonce': apiNonce,
17 17 };
18 18 this.swrOptions = {
19 19 use: [lagData],
20 + ...swrConfig,
20 21 onErrorRetry: (error, key, config, revalidate, {retryCount}) => {
21 22 //don't retry if we cancelled the initial request
22 23 if (error.name == 'AbortError') return;
23 24 if (retryCount >= 5) return;
@@ -41,9 +42,11 @@
41 42 signal: signal,
42 43 headers: this.headers,
43 44 }).then((res) => {
44 45 if (!res.ok) {
45 - throw new Error();
46 + return res.text().then((errorMessage) => {
47 + throw new Error(errorMessage);
48 + });
46 49 }
47 50 return res.json();
48 51 });
49 52 };
@@ -66,8 +69,17 @@
66 69 testMode,
67 70 ...filters,
68 71 },
69 72 this.fetcher,
73 + this.swrOptions
74 + );
75 + return {data, error, mutate, isValidating};
76 + };
77 +
78 + useStats = (testMode) => {
79 + const {data, error, mutate, isValidating} = useSWR(
80 + {testMode},
81 + (params) => this.fetchWithArgs('/stats', params, 'GET'),
70 82 this.swrOptions
71 83 );
72 84 return {data, error, mutate, isValidating};
73 85 };