@steroidsjs/core 2.2.57 → 2.2.60
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/hooks/useFetch.d.ts +2 -0
- package/hooks/useFetch.js +19 -7
- package/hooks/useFile.js +2 -5
- package/package.json +1 -1
- package/ui/form/FileField/FileField.js +3 -2
package/hooks/useFetch.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
1
2
|
import { IComponents } from '../providers/ComponentsProvider';
|
|
2
3
|
import { IApiMethod } from '../components/ApiComponent';
|
|
3
4
|
declare global {
|
|
@@ -22,6 +23,7 @@ export interface IFetchResult {
|
|
|
22
23
|
} | any;
|
|
23
24
|
isLoading: boolean;
|
|
24
25
|
fetch?: (newParams?: Record<string, unknown>) => void;
|
|
26
|
+
axiosError: AxiosError | null;
|
|
25
27
|
}
|
|
26
28
|
export declare const normalizeConfig: (config: any) => any;
|
|
27
29
|
export declare const getConfigId: (config: any) => any;
|
package/hooks/useFetch.js
CHANGED
|
@@ -111,7 +111,8 @@ function useFetch(rawConfig) {
|
|
|
111
111
|
var preloadedDataByConfigId = (preloadedData && configId) ? preloadedData[configId] : null;
|
|
112
112
|
// State for data and loading flag
|
|
113
113
|
var _b = react_1.useState(preloadedDataByConfigId || null), data = _b[0], setData = _b[1];
|
|
114
|
-
var _c = react_1.useState(
|
|
114
|
+
var _c = react_1.useState(null), axiosError = _c[0], setAxiosError = _c[1];
|
|
115
|
+
var _d = react_1.useState(!!config && !data), isLoading = _d[0], setIsLoading = _d[1];
|
|
115
116
|
// Cancel tokens
|
|
116
117
|
var cancelTokens = react_1.useRef([]);
|
|
117
118
|
var addCancelToken = function (token) { return cancelTokens.current.push(token); };
|
|
@@ -120,7 +121,7 @@ function useFetch(rawConfig) {
|
|
|
120
121
|
var fetch = react_1.useCallback(function (newConfig) {
|
|
121
122
|
if (newConfig === void 0) { newConfig = null; }
|
|
122
123
|
return __awaiter(_this, void 0, void 0, function () {
|
|
123
|
-
var _a;
|
|
124
|
+
var _a, error_1;
|
|
124
125
|
return __generator(this, function (_b) {
|
|
125
126
|
switch (_b.label) {
|
|
126
127
|
case 0:
|
|
@@ -128,15 +129,26 @@ function useFetch(rawConfig) {
|
|
|
128
129
|
setConfig(__assign(__assign(__assign({}, config), newConfig), { params: __assign(__assign({}, config === null || config === void 0 ? void 0 : config.params), newConfig === null || newConfig === void 0 ? void 0 : newConfig.params) }));
|
|
129
130
|
}
|
|
130
131
|
setData(null);
|
|
131
|
-
if (!config) return [3 /*break*/,
|
|
132
|
+
if (!config) return [3 /*break*/, 5];
|
|
132
133
|
setIsLoading(true);
|
|
134
|
+
_b.label = 1;
|
|
135
|
+
case 1:
|
|
136
|
+
_b.trys.push([1, 3, , 4]);
|
|
133
137
|
_a = setData;
|
|
134
138
|
return [4 /*yield*/, exports.fetchData(config, components, addCancelToken)];
|
|
135
|
-
case
|
|
139
|
+
case 2:
|
|
136
140
|
_a.apply(void 0, [_b.sent()]);
|
|
141
|
+
return [3 /*break*/, 4];
|
|
142
|
+
case 3:
|
|
143
|
+
error_1 = _b.sent();
|
|
144
|
+
if (error_1.isAxiosError) {
|
|
145
|
+
setAxiosError(error_1);
|
|
146
|
+
}
|
|
147
|
+
return [3 /*break*/, 4];
|
|
148
|
+
case 4:
|
|
137
149
|
setIsLoading(false);
|
|
138
|
-
_b.label =
|
|
139
|
-
case
|
|
150
|
+
_b.label = 5;
|
|
151
|
+
case 5: return [2 /*return*/];
|
|
140
152
|
}
|
|
141
153
|
});
|
|
142
154
|
});
|
|
@@ -150,6 +162,6 @@ function useFetch(rawConfig) {
|
|
|
150
162
|
react_use_1.useUpdateEffect(function () {
|
|
151
163
|
fetch();
|
|
152
164
|
}, [fetch]);
|
|
153
|
-
return { data: data, isLoading: isLoading, fetch: fetch };
|
|
165
|
+
return { data: data, isLoading: isLoading, fetch: fetch, axiosError: axiosError };
|
|
154
166
|
}
|
|
155
167
|
exports["default"] = useFetch;
|
package/hooks/useFile.js
CHANGED
|
@@ -66,12 +66,9 @@ function useFile(props) {
|
|
|
66
66
|
uploader.queue.add(normalizedInitialFiles_1
|
|
67
67
|
.map(function (item) {
|
|
68
68
|
var path = item.title || item.label || item.uid || item.id;
|
|
69
|
-
var resultHttpMessage = {
|
|
70
|
-
id: item.id || item.uid,
|
|
71
|
-
images: item.thumbnailUrl
|
|
69
|
+
var resultHttpMessage = __assign(__assign({}, item), { id: item.id || item.uid, images: item.thumbnailUrl
|
|
72
70
|
? [{ url: item.thumbnailUrl }]
|
|
73
|
-
: null
|
|
74
|
-
};
|
|
71
|
+
: null });
|
|
75
72
|
var file = uploader.queue.getByUid(item.uid);
|
|
76
73
|
if (file) {
|
|
77
74
|
file.setPath(path);
|
package/package.json
CHANGED
|
@@ -57,13 +57,14 @@ function FileField(props) {
|
|
|
57
57
|
uid: file.getUid(),
|
|
58
58
|
fileId: data.id || null,
|
|
59
59
|
title: file.getName(),
|
|
60
|
-
size:
|
|
60
|
+
size: data.size || data.fileSize,
|
|
61
61
|
disabled: props.disabled,
|
|
62
62
|
showRemove: props.showRemove,
|
|
63
63
|
onRemove: function () { return onRemove(file); },
|
|
64
64
|
error: null,
|
|
65
65
|
image: null,
|
|
66
|
-
progress: null
|
|
66
|
+
progress: null,
|
|
67
|
+
item: data
|
|
67
68
|
};
|
|
68
69
|
// Add error
|
|
69
70
|
if (file.getResult() === File_1["default"].RESULT_ERROR) {
|