react-usespinner 1.0.14 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/usespinner.js +25 -9
- package/package.json +1 -1
package/dist/usespinner.js
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
2
13
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
3
14
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4
15
|
if (ar || !(i in from)) {
|
@@ -16,12 +27,16 @@ var useSpinner = function (globalOptions) {
|
|
16
27
|
var _a = (0, react_1.useState)([]), actions = _a[0], setActions = _a[1];
|
17
28
|
// set a timer that every second checks if any actions can be closed
|
18
29
|
(0, react_1.useEffect)(function () {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
if (actions.length > 0) {
|
31
|
+
var timer_1 = setTimeout(function () {
|
32
|
+
if (actions) {
|
33
|
+
setActions(function (prev) {
|
34
|
+
return prev.filter(function (item) { return item.endtime > Date.now(); });
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}, 1000);
|
38
|
+
return function () { return clearTimeout(timer_1); };
|
39
|
+
}
|
25
40
|
}, [actions]);
|
26
41
|
// Allow the start of a new Action to be tracked
|
27
42
|
var start = function (name, options) {
|
@@ -40,16 +55,17 @@ var useSpinner = function (globalOptions) {
|
|
40
55
|
setActions([]);
|
41
56
|
};
|
42
57
|
var busy = function () {
|
58
|
+
console.log("Busy = ", actions && actions.length > 0);
|
43
59
|
return actions && actions.length > 0;
|
44
60
|
};
|
45
61
|
// JSX component used to wrap spinner of choice
|
46
62
|
var SpinnerContainer = function (_a) {
|
47
63
|
var spinner = _a.spinner, children = _a.children;
|
48
64
|
// If no active Actions then dont display anything
|
49
|
-
if (
|
50
|
-
return (0, jsx_runtime_1.jsx)(
|
65
|
+
if (busy()) {
|
66
|
+
return (0, jsx_runtime_1.jsx)("div", __assign({ className: "useSpinner" }, { children: spinner }));
|
51
67
|
}
|
52
|
-
return (0, jsx_runtime_1.jsx)("div", { children: children });
|
68
|
+
return (0, jsx_runtime_1.jsx)("div", __assign({ className: "useSpinner" }, { children: children }));
|
53
69
|
};
|
54
70
|
// return hook values
|
55
71
|
return { start: start, end: end, clear: clear, busy: busy, SpinnerContainer: SpinnerContainer };
|
package/package.json
CHANGED