namirasoft-site-react 1.4.328 → 1.4.330
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NSBarNotificationProps } from "../components/NSBarNotification";
|
|
2
2
|
import { IStorage } from "namirasoft-core";
|
|
3
3
|
export declare class NSNotifier {
|
|
4
|
+
private static mutex_mofify;
|
|
5
|
+
private static mutex_set;
|
|
4
6
|
private storage;
|
|
5
7
|
private setState;
|
|
6
8
|
timeout: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { NSBarNotificationColor, NotificationType } from "../components/NSBarNotification";
|
|
3
3
|
import { BaseUUID, TimeOperation } from "namirasoft-core";
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
4
5
|
export class NSNotifier {
|
|
5
6
|
constructor(storage, setState) {
|
|
6
7
|
this.timeout = 5000;
|
|
@@ -24,31 +25,35 @@ export class NSNotifier {
|
|
|
24
25
|
ans = ans.filter(x => {
|
|
25
26
|
if (x.expired_at) {
|
|
26
27
|
let expired_at = new Date(x.expired_at);
|
|
27
|
-
|
|
28
|
-
console.log({ expired_at, now, result });
|
|
29
|
-
return result;
|
|
28
|
+
return expired_at >= now;
|
|
30
29
|
}
|
|
31
30
|
return false;
|
|
32
31
|
});
|
|
33
32
|
return ans;
|
|
34
33
|
}
|
|
35
34
|
setNotifications(notifications) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
n.expired_at
|
|
35
|
+
NSNotifier.mutex_set.runExclusive(() => {
|
|
36
|
+
notifications.forEach(n => {
|
|
37
|
+
if (!n.expired_at)
|
|
38
|
+
n.expired_at = TimeOperation.millisecondsLater(this.timeout, new Date());
|
|
39
|
+
});
|
|
40
|
+
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
41
|
+
this.setState();
|
|
39
42
|
});
|
|
40
|
-
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
41
|
-
this.setState();
|
|
42
43
|
}
|
|
43
44
|
delNotification(id) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
NSNotifier.mutex_mofify.runExclusive(() => {
|
|
46
|
+
let notifications = this.getNotifications();
|
|
47
|
+
notifications = notifications.filter(x => x.id !== id);
|
|
48
|
+
this.setNotifications(notifications);
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
notify(message) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
NSNotifier.mutex_mofify.runExclusive(() => {
|
|
53
|
+
let notifications = this.getNotifications();
|
|
54
|
+
notifications.push(message);
|
|
55
|
+
this.setNotifications(notifications);
|
|
56
|
+
});
|
|
52
57
|
setTimeout(() => {
|
|
53
58
|
this.delNotification(message.id);
|
|
54
59
|
}, this.timeout);
|
|
@@ -81,4 +86,6 @@ export class NSNotifier {
|
|
|
81
86
|
this.notify({ id, text, type: NotificationType.Error, color: NSBarNotificationColor.RED });
|
|
82
87
|
}
|
|
83
88
|
}
|
|
89
|
+
NSNotifier.mutex_mofify = new Mutex();
|
|
90
|
+
NSNotifier.mutex_set = new Mutex();
|
|
84
91
|
//# sourceMappingURL=NSNotifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NSNotifier.js","sourceRoot":"","sources":["../../src/routing/NSNotifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAA0B,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,QAAQ,EAAY,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"NSNotifier.js","sourceRoot":"","sources":["../../src/routing/NSNotifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAA0B,gBAAgB,EAAE,MAAM,iCAAiC,CA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CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,IAAI,GAAW,EAAE,CAAC;QACtB,IAAI,KAAK,YAAY,KAAK,EAC1B,CAAC;YACG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;YACrB,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC;gBACzB,IAAI,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI;oBACpB,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvC,CAAC;;YAEG,IAAI,GAAG,KAAK,CAAC;QACjB,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,sBAAsB,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/F,CAAC;;AArGc,uBAAY,GAAU,IAAI,KAAK,EAAE,AAArB,CAAsB;AAClC,oBAAS,GAAU,IAAI,KAAK,EAAE,AAArB,CAAsB"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { NSBarNotificationColor, NSBarNotificationProps, NotificationType } from "../components/NSBarNotification";
|
|
3
3
|
import { BaseUUID, IStorage, TimeOperation } from "namirasoft-core";
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
4
5
|
|
|
5
6
|
export class NSNotifier
|
|
6
7
|
{
|
|
8
|
+
private static mutex_mofify: Mutex = new Mutex();
|
|
9
|
+
private static mutex_set: Mutex = new Mutex();
|
|
7
10
|
private storage: IStorage;
|
|
8
11
|
private setState: () => void;
|
|
9
12
|
public timeout: number = 5000;
|
|
@@ -32,9 +35,7 @@ export class NSNotifier
|
|
|
32
35
|
if (x.expired_at)
|
|
33
36
|
{
|
|
34
37
|
let expired_at = new Date(x.expired_at);
|
|
35
|
-
|
|
36
|
-
console.log({ expired_at, now, result });
|
|
37
|
-
return result;
|
|
38
|
+
return expired_at >= now;
|
|
38
39
|
}
|
|
39
40
|
return false;
|
|
40
41
|
})
|
|
@@ -42,25 +43,34 @@ export class NSNotifier
|
|
|
42
43
|
}
|
|
43
44
|
setNotifications(notifications: NSBarNotificationProps[]): void
|
|
44
45
|
{
|
|
45
|
-
|
|
46
|
+
NSNotifier.mutex_set.runExclusive(() =>
|
|
46
47
|
{
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
notifications.forEach(n =>
|
|
49
|
+
{
|
|
50
|
+
if (!n.expired_at)
|
|
51
|
+
n.expired_at = TimeOperation.millisecondsLater(this.timeout, new Date());
|
|
52
|
+
});
|
|
53
|
+
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
54
|
+
this.setState();
|
|
49
55
|
});
|
|
50
|
-
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
51
|
-
this.setState();
|
|
52
56
|
}
|
|
53
57
|
delNotification(id: string): void
|
|
54
58
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
NSNotifier.mutex_mofify.runExclusive(() =>
|
|
60
|
+
{
|
|
61
|
+
let notifications: NSBarNotificationProps[] = this.getNotifications();
|
|
62
|
+
notifications = notifications.filter(x => x.id !== id);
|
|
63
|
+
this.setNotifications(notifications);
|
|
64
|
+
});
|
|
58
65
|
}
|
|
59
66
|
private notify(message: NSBarNotificationProps)
|
|
60
67
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
NSNotifier.mutex_mofify.runExclusive(() =>
|
|
69
|
+
{
|
|
70
|
+
let notifications: NSBarNotificationProps[] = this.getNotifications();
|
|
71
|
+
notifications.push(message);
|
|
72
|
+
this.setNotifications(notifications);
|
|
73
|
+
});
|
|
64
74
|
setTimeout(() =>
|
|
65
75
|
{
|
|
66
76
|
this.delNotification(message.id);
|