@steroidsjs/core 2.2.58 → 2.2.61

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/hoc/file.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface IFileHocInput {
15
15
  uploaderConfig?: {
16
16
  useFormData?: boolean;
17
17
  fileFieldName?: string;
18
- };
18
+ } | any;
19
19
  }
20
20
  export interface IFileHocOutput {
21
21
  uploader?: any;
@@ -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(!!config && !data), isLoading = _c[0], setIsLoading = _c[1];
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*/, 2];
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 1:
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 = 2;
139
- case 2: return [2 /*return*/];
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
@@ -39,7 +39,12 @@ function generateBackendUrl(props) {
39
39
  });
40
40
  }
41
41
  function useFile(props) {
42
- var uploader = useInitial_1["default"](function () { return new fileup_core_1["default"](__assign(__assign({ dropArea: {}, backendUrl: generateBackendUrl(props), uploaderConfig: __assign({}, props.uploaderConfig) }, props.uploader), { form: __assign(__assign({}, (props.uploader && props.uploader.form)), { multiple: props.multiple }) })); });
42
+ var http = index_1.useComponents().http;
43
+ http.getAccessToken(); // TODO Run promise..
44
+ var uploader = useInitial_1["default"](function () {
45
+ var _a;
46
+ return new fileup_core_1["default"](__assign(__assign({ dropArea: {}, backendUrl: generateBackendUrl(props), uploaderConfig: __assign(__assign({}, props.uploaderConfig), { headers: __assign(__assign({}, (_a = props.uploaderConfig) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: 'Bearer ' + http._accessToken }) }) }, props.uploader), { form: __assign(__assign({}, (props.uploader && props.uploader.form)), { multiple: props.multiple }) }));
47
+ });
43
48
  /**
44
49
  * Force component update when file status or progress changes
45
50
  * @private
@@ -66,12 +71,9 @@ function useFile(props) {
66
71
  uploader.queue.add(normalizedInitialFiles_1
67
72
  .map(function (item) {
68
73
  var path = item.title || item.label || item.uid || item.id;
69
- var resultHttpMessage = {
70
- id: item.id || item.uid,
71
- images: item.thumbnailUrl
74
+ var resultHttpMessage = __assign(__assign({}, item), { id: item.id || item.uid, images: item.thumbnailUrl
72
75
  ? [{ url: item.thumbnailUrl }]
73
- : null
74
- };
76
+ : null });
75
77
  var file = uploader.queue.getByUid(item.uid);
76
78
  if (file) {
77
79
  file.setPath(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.58",
3
+ "version": "2.2.61",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -63,7 +63,8 @@ function FileField(props) {
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) {