zavadil-react-common 1.2.111 → 1.2.112
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.
|
@@ -2,24 +2,33 @@ import {UserAlert, UserAlerts, UserAlertType} from 'zavadil-ts-common';
|
|
|
2
2
|
import {useEffect, useState} from "react";
|
|
3
3
|
import UserAlertWidget from "./UserAlertWidget";
|
|
4
4
|
import UserAlertTypeIcon from "./UserAlertTypeIcon";
|
|
5
|
-
import {
|
|
5
|
+
import {Stack} from "react-bootstrap";
|
|
6
|
+
import {IconButton} from "../forms";
|
|
7
|
+
import {BsEye, BsTrash} from "react-icons/bs";
|
|
6
8
|
|
|
7
9
|
export type UserAlertsWidgetProps = {
|
|
8
10
|
userAlerts: UserAlerts;
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
export function UserAlertsWidget({userAlerts}: UserAlertsWidgetProps) {
|
|
12
|
-
const [
|
|
14
|
+
const [totalAlerts, setTotalAlerts] = useState<number>(userAlerts.alerts.length);
|
|
15
|
+
const [renderedAlerts, setRenderedAlerts] = useState<UserAlert[]>([...userAlerts.visibleAlerts]);
|
|
13
16
|
const [summary, setSummary] = useState<Map<UserAlertType, number>>(userAlerts.getSummary());
|
|
14
17
|
|
|
15
18
|
useEffect(() => {
|
|
16
19
|
userAlerts.addOnChangeHandler(() => {
|
|
17
|
-
|
|
20
|
+
setTotalAlerts(userAlerts.alerts.length);
|
|
21
|
+
setRenderedAlerts([...userAlerts.visibleAlerts]);
|
|
18
22
|
setSummary(userAlerts.getSummary());
|
|
19
23
|
});
|
|
24
|
+
const handle = setInterval(
|
|
25
|
+
() => userAlerts.updateVisibility(),
|
|
26
|
+
100
|
|
27
|
+
);
|
|
28
|
+
return () => clearInterval(handle);
|
|
20
29
|
}, [userAlerts]);
|
|
21
30
|
|
|
22
|
-
if (
|
|
31
|
+
if (totalAlerts <= 0) return <></>;
|
|
23
32
|
|
|
24
33
|
return (
|
|
25
34
|
<div className="user-alerts border rounded bg-body text-body position-fixed text-end" style={{bottom: 15, right: 15, zIndex: 2147483647}}>
|
|
@@ -32,7 +41,7 @@ export function UserAlertsWidget({userAlerts}: UserAlertsWidgetProps) {
|
|
|
32
41
|
}
|
|
33
42
|
<div className="p-2">
|
|
34
43
|
<Stack direction="horizontal" gap={2} className="justify-content-end align-items-center">
|
|
35
|
-
<
|
|
44
|
+
<IconButton size="sm" variant="primary" onClick={() => userAlerts.hideAll()} icon={<BsEye/>}>Hide</IconButton>
|
|
36
45
|
{
|
|
37
46
|
Array.from(summary.entries()).map(
|
|
38
47
|
(entry, index) => (
|
|
@@ -45,6 +54,7 @@ export function UserAlertsWidget({userAlerts}: UserAlertsWidgetProps) {
|
|
|
45
54
|
)
|
|
46
55
|
)
|
|
47
56
|
}
|
|
57
|
+
<IconButton size="sm" variant="danger" onClick={() => userAlerts.reset()} icon={<BsTrash/>}>Reset</IconButton>
|
|
48
58
|
</Stack>
|
|
49
59
|
</div>
|
|
50
60
|
</div>
|