@blocklet/ui-react 3.2.15 → 3.2.16
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,73 +1,77 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { IconButton as
|
|
5
|
-
import { useSnackbar as
|
|
6
|
-
import
|
|
7
|
-
import { useCreation as
|
|
8
|
-
import { WELLKNOWN_SERVICE_PATH_PREFIX as
|
|
9
|
-
import
|
|
10
|
-
import { compareVersions as
|
|
11
|
-
import { joinURL as
|
|
12
|
-
import { useListenWsClient as
|
|
13
|
-
import
|
|
14
|
-
const E =
|
|
15
|
-
id:
|
|
16
|
-
severity:
|
|
17
|
-
componentDid:
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import S from "prop-types";
|
|
3
|
+
import { useMemo as L, useCallback as T, useEffect as $ } from "react";
|
|
4
|
+
import { IconButton as B, Badge as P } from "@mui/material";
|
|
5
|
+
import { useSnackbar as V } from "notistack";
|
|
6
|
+
import x from "@arcblock/icons/lib/Notification";
|
|
7
|
+
import { useCreation as s } from "ahooks";
|
|
8
|
+
import { WELLKNOWN_SERVICE_PATH_PREFIX as W, ROLES as A, EVENTS as O } from "@abtnode/constant";
|
|
9
|
+
import j from "@arcblock/react-hooks/lib/useBrowser";
|
|
10
|
+
import { compareVersions as F } from "@arcblock/ux/lib/Util";
|
|
11
|
+
import { joinURL as H, withQuery as R } from "ufo";
|
|
12
|
+
import { useListenWsClient as K } from "./ws.js";
|
|
13
|
+
import M from "../Notifications/Snackbar.js";
|
|
14
|
+
const E = H(W, "user", "notifications"), z = (r) => R(E, {
|
|
15
|
+
id: r.id,
|
|
16
|
+
severity: r.severity || "all",
|
|
17
|
+
componentDid: r.source === "system" ? "system" : r.componentDid || "all"
|
|
18
18
|
});
|
|
19
|
-
function
|
|
20
|
-
const { unReadCount: l, user:
|
|
21
|
-
() => `${window.blocklet.did}/${e}/${
|
|
19
|
+
function q({ session: r = {} }) {
|
|
20
|
+
const { unReadCount: l, user: t, setUnReadCount: i } = r, e = s(() => t?.did, [t]), h = s(() => t?.role && [A.ADMIN, A.OWNER].includes(t?.role), [t?.role]), { enqueueSnackbar: N } = V(), d = j(), u = L(() => !e || t?.isPreviewUser || e === window.blocklet.did, [e, t]), k = L(() => d.arcSphere || d.wallet, [d]), y = s(() => window.blocklet?.serverVersion, []), n = K("user"), a = s(
|
|
21
|
+
() => `${window.blocklet.did}/${e}/${O.NOTIFICATION_BLOCKLET_CREATE}`,
|
|
22
22
|
[e]
|
|
23
|
-
), m =
|
|
24
|
-
() => `${window.blocklet.did}/${e}/${
|
|
23
|
+
), m = s(
|
|
24
|
+
() => `${window.blocklet.did}/${e}/${O.NOTIFICATION_BLOCKLET_READ}`,
|
|
25
25
|
[e]
|
|
26
|
-
),
|
|
27
|
-
(
|
|
28
|
-
const { receivers: v } =
|
|
29
|
-
if (
|
|
26
|
+
), p = T(
|
|
27
|
+
(o) => {
|
|
28
|
+
const { receivers: v, source: w } = o ?? {}, { receiver: C } = v[0] ?? {};
|
|
29
|
+
if (C === e && (h || w !== "system")) {
|
|
30
30
|
i((b) => b + 1);
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
const b =
|
|
34
|
-
|
|
35
|
-
variant:
|
|
36
|
-
autoHideDuration:
|
|
31
|
+
const U = F(y, "1.16.42-beta-20250407");
|
|
32
|
+
if (!k && o.source === "component" && U) {
|
|
33
|
+
const b = z(o), { severity: I, description: _ } = o || {}, g = ["error", "warning"].includes(I) || o.sticky;
|
|
34
|
+
N(_, {
|
|
35
|
+
variant: I,
|
|
36
|
+
autoHideDuration: g ? null : 5e3,
|
|
37
|
+
anchorOrigin: {
|
|
38
|
+
vertical: "top",
|
|
39
|
+
horizontal: "center"
|
|
40
|
+
},
|
|
37
41
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
38
|
-
content: (
|
|
42
|
+
content: (D) => /* @__PURE__ */ c(M, { viewAllUrl: b, keyId: D, notification: o })
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
|
-
[e, i,
|
|
44
|
-
),
|
|
45
|
-
(
|
|
46
|
-
const { receiver: v, readCount: w } =
|
|
47
|
+
[e, i, N, y, k, h]
|
|
48
|
+
), f = T(
|
|
49
|
+
(o) => {
|
|
50
|
+
const { receiver: v, readCount: w } = o ?? {};
|
|
47
51
|
v === e && i((C) => Math.max(C - w, 0));
|
|
48
52
|
},
|
|
49
53
|
[e, i]
|
|
50
54
|
);
|
|
51
|
-
return $(() => (
|
|
52
|
-
|
|
53
|
-
}), [
|
|
54
|
-
|
|
55
|
+
return $(() => (n && !u && (n.on(a, p), n.on(m, f)), () => {
|
|
56
|
+
n && !u && (n.off(a, p), n.off(m, f));
|
|
57
|
+
}), [n, i, p, a, f, m, u]), !r.user || !E ? null : /* @__PURE__ */ c(
|
|
58
|
+
B,
|
|
55
59
|
{
|
|
56
60
|
size: "medium",
|
|
57
61
|
variant: "outlined",
|
|
58
|
-
href:
|
|
62
|
+
href: R(E, { read: l <= 0 }),
|
|
59
63
|
sx: {
|
|
60
64
|
"&:hover": {
|
|
61
65
|
borderRadius: "50%"
|
|
62
66
|
}
|
|
63
67
|
},
|
|
64
|
-
children: /* @__PURE__ */
|
|
68
|
+
children: /* @__PURE__ */ c(P, { badgeContent: l, color: "error", invisible: l === 0, children: /* @__PURE__ */ c(x, { style: { width: "auto", height: 24 } }) })
|
|
65
69
|
}
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
session:
|
|
72
|
+
q.propTypes = {
|
|
73
|
+
session: S.object
|
|
70
74
|
};
|
|
71
75
|
export {
|
|
72
|
-
|
|
76
|
+
q as default
|
|
73
77
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.16",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@abtnode/constant": "^1.17.5",
|
|
37
37
|
"@abtnode/util": "^1.17.5",
|
|
38
|
-
"@arcblock/bridge": "3.2.
|
|
39
|
-
"@arcblock/icons": "3.2.
|
|
40
|
-
"@arcblock/react-hooks": "3.2.
|
|
38
|
+
"@arcblock/bridge": "3.2.16",
|
|
39
|
+
"@arcblock/icons": "3.2.16",
|
|
40
|
+
"@arcblock/react-hooks": "3.2.16",
|
|
41
41
|
"@arcblock/ws": "^1.27.15",
|
|
42
42
|
"@blocklet/did-space-react": "^1.2.10",
|
|
43
43
|
"@iconify-icons/logos": "^1.2.36",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@arcblock/did-connect-react": "3.2.
|
|
85
|
+
"@arcblock/did-connect-react": "3.2.16",
|
|
86
86
|
"@types/dompurify": "^3.2.0",
|
|
87
87
|
"@types/ua-parser-js": "^0.7.39",
|
|
88
88
|
"@types/validator": "^13.15.2",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"jest": "^29.7.0",
|
|
91
91
|
"unbuild": "^2.0.0"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "cc7ec117370b11df3e5e1b60120af8f5e2e82cb7"
|
|
94
94
|
}
|
|
@@ -4,7 +4,7 @@ import { IconButton, Badge } from '@mui/material';
|
|
|
4
4
|
import { useSnackbar } from 'notistack';
|
|
5
5
|
import NotificationsOutlinedIcon from '@arcblock/icons/lib/Notification';
|
|
6
6
|
import { useCreation } from 'ahooks';
|
|
7
|
-
import { EVENTS, WELLKNOWN_SERVICE_PATH_PREFIX } from '@abtnode/constant';
|
|
7
|
+
import { EVENTS, WELLKNOWN_SERVICE_PATH_PREFIX, ROLES } from '@abtnode/constant';
|
|
8
8
|
import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
|
|
9
9
|
import { compareVersions } from '@arcblock/ux/lib/Util';
|
|
10
10
|
import { joinURL, withQuery } from 'ufo';
|
|
@@ -25,6 +25,8 @@ export default function NotificationAddon({ session = {} }) {
|
|
|
25
25
|
const { unReadCount, user, setUnReadCount } = session;
|
|
26
26
|
const userDid = useCreation(() => user?.did, [user]);
|
|
27
27
|
|
|
28
|
+
const isAdmin = useCreation(() => user?.role && [ROLES.ADMIN, ROLES.OWNER].includes(user?.role), [user?.role]);
|
|
29
|
+
|
|
28
30
|
const { enqueueSnackbar } = useSnackbar();
|
|
29
31
|
const browser = useBrowser();
|
|
30
32
|
|
|
@@ -54,11 +56,11 @@ export default function NotificationAddon({ session = {} }) {
|
|
|
54
56
|
|
|
55
57
|
const listenCallback = useCallback(
|
|
56
58
|
(notification) => {
|
|
57
|
-
const { receivers } = notification ?? {};
|
|
59
|
+
const { receivers, source } = notification ?? {};
|
|
58
60
|
|
|
59
61
|
const { receiver: notificationReceiver } = receivers[0] ?? {};
|
|
60
|
-
|
|
61
|
-
if (notificationReceiver === userDid) {
|
|
62
|
+
const shouldUpdate = isAdmin || source !== 'system';
|
|
63
|
+
if (notificationReceiver === userDid && shouldUpdate) {
|
|
62
64
|
setUnReadCount((x) => x + 1);
|
|
63
65
|
// 显示通知, 如果是系统通知则不需要显示, 如果是移动端不需要显示
|
|
64
66
|
// 兼容代码,如果 server 没有升级那么不需要提示
|
|
@@ -70,13 +72,17 @@ export default function NotificationAddon({ session = {} }) {
|
|
|
70
72
|
enqueueSnackbar(description, {
|
|
71
73
|
variant: severity,
|
|
72
74
|
autoHideDuration: disableAutoHide ? null : 5000,
|
|
75
|
+
anchorOrigin: {
|
|
76
|
+
vertical: 'top',
|
|
77
|
+
horizontal: 'center',
|
|
78
|
+
},
|
|
73
79
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
74
80
|
content: (key) => <NotificationSnackbar viewAllUrl={link} keyId={key} notification={notification} />,
|
|
75
81
|
});
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
},
|
|
79
|
-
[userDid, setUnReadCount, enqueueSnackbar, serverVersion, hiddenNotificationToast]
|
|
85
|
+
[userDid, setUnReadCount, enqueueSnackbar, serverVersion, hiddenNotificationToast, isAdmin]
|
|
80
86
|
);
|
|
81
87
|
|
|
82
88
|
const readListenCallback = useCallback(
|