@blocklet/ui-react 2.10.74 → 2.10.76

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.
@@ -67,6 +67,7 @@ export default function ThirdPartyItem({
67
67
  }).then(resolve).catch(reject);
68
68
  close();
69
69
  },
70
+ // @ts-ignore
70
71
  onCancel: resolve
71
72
  });
72
73
  } else {
@@ -147,10 +147,7 @@ export default function UserBasicInfo({
147
147
  {
148
148
  title: !loading && translate(translations, "refreshProfile.title", locale),
149
149
  sx: { display: "flex", alignItems: "center" },
150
- children: loading ? (
151
- // @ts-expect-error
152
- /* @__PURE__ */ jsx(CircularProgress, { size: "16px", sx: { color: theme?.colors?.primary, ml: 0.5 } })
153
- ) : /* @__PURE__ */ jsx(RefreshOutlinedIcon, { onClick: refreshProfile })
150
+ children: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: "16px", sx: { color: theme?.colors?.primary, ml: 0.5 } }) : /* @__PURE__ */ jsx(RefreshOutlinedIcon, { onClick: refreshProfile })
154
151
  }
155
152
  )
156
153
  ] }) : null
@@ -10,6 +10,8 @@ import { getVisitorId } from "@arcblock/ux/lib/Util";
10
10
  import { useConfirm } from "@arcblock/ux/lib/Dialog";
11
11
  import pAll from "p-all";
12
12
  import { Box, Button, Tooltip, Typography } from "@mui/material";
13
+ import { useContext } from "react";
14
+ import { SessionContext } from "@arcblock/did-connect/lib/Session";
13
15
  import UserSessionInfo from "./user-session-info.js";
14
16
  import { client } from "../../libs/client.js";
15
17
  import { translations } from "../libs/locales.js";
@@ -27,6 +29,7 @@ export default function UserSessions({
27
29
  showAction = true,
28
30
  showUser = true
29
31
  }) {
32
+ const { session } = useContext(SessionContext);
30
33
  const currentVisitorId = getVisitorId();
31
34
  const { locale } = useLocaleContext();
32
35
  const { confirmApi, confirmHolder } = useConfirm();
@@ -34,11 +37,11 @@ export default function UserSessions({
34
37
  return translate(translations, key, locale, "en", data);
35
38
  });
36
39
  const getData = useMemoizedFn(async () => {
37
- let data = user?.userSessions;
38
- if (!data) {
39
- data = await client.userSession.getUserSessions({ did: user.did });
40
- }
40
+ let data = user?.userSessions || [];
41
41
  try {
42
+ if (!data && session.user) {
43
+ data = await client.userSession.getUserSessionsByMyself();
44
+ }
42
45
  const ipIndexList = data?.map((x, index) => [index, x.lastLoginIp]).filter((x) => !!x[1]);
43
46
  const ipList = ipIndexList?.map((x) => x[1]);
44
47
  const result = await batchIp2Region(ipList);
@@ -187,10 +190,7 @@ export default function UserSessions({
187
190
  options: {
188
191
  customBodyRenderLite: (rawIndex) => {
189
192
  const x = safeData[rawIndex];
190
- return x.createdAt ? (
191
- // @ts-expect-error
192
- /* @__PURE__ */ jsx(RelativeTime, { value: x.createdAt, relativeRange: 3 * 86400 * 1e3, locale })
193
- ) : t("unknown");
193
+ return x.createdAt ? /* @__PURE__ */ jsx(RelativeTime, { value: x.createdAt, relativeRange: 3 * 86400 * 1e3, locale }) : t("unknown");
194
194
  }
195
195
  }
196
196
  },
@@ -200,10 +200,7 @@ export default function UserSessions({
200
200
  options: {
201
201
  customBodyRenderLite: (rawIndex) => {
202
202
  const x = safeData[rawIndex];
203
- return x.status === "expired" ? t("expired") : (
204
- // @ts-expect-error
205
- /* @__PURE__ */ jsx(RelativeTime, { value: x.updatedAt, relativeRange: 3 * 86400 * 1e3, locale })
206
- );
203
+ return x.status === "expired" ? t("expired") : /* @__PURE__ */ jsx(RelativeTime, { value: x.updatedAt, relativeRange: 3 * 86400 * 1e3, locale });
207
204
  }
208
205
  }
209
206
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.10.74",
3
+ "version": "2.10.76",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -32,9 +32,9 @@
32
32
  "url": "https://github.com/ArcBlock/ux/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@arcblock/bridge": "^2.10.74",
36
- "@arcblock/react-hooks": "^2.10.74",
37
- "@blocklet/did-space-react": "^0.5.72",
35
+ "@arcblock/bridge": "^2.10.76",
36
+ "@arcblock/react-hooks": "^2.10.76",
37
+ "@blocklet/did-space-react": "^0.5.75",
38
38
  "@iconify-icons/logos": "^1.2.36",
39
39
  "@iconify-icons/material-symbols": "^1.2.58",
40
40
  "@iconify/react": "^4.1.1",
@@ -80,5 +80,5 @@
80
80
  "jest": "^29.7.0",
81
81
  "unbuild": "^2.0.0"
82
82
  },
83
- "gitHead": "e9ebc573e8c38bc82a6c2a1ff58bae932dd59ec6"
83
+ "gitHead": "b128f96e35c7ea4b1c78b9c9c7a8bf5499c118ce"
84
84
  }
@@ -85,6 +85,7 @@ export default function ThirdPartyItem({
85
85
  .catch(reject);
86
86
  close();
87
87
  },
88
+ // @ts-ignore
88
89
  onCancel: resolve,
89
90
  });
90
91
  } else {
@@ -157,7 +157,6 @@ export default function UserBasicInfo({
157
157
  title={!loading && translate(translations, 'refreshProfile.title', locale)}
158
158
  sx={{ display: 'flex', alignItems: 'center' }}>
159
159
  {loading ? (
160
- // @ts-expect-error
161
160
  <CircularProgress size="16px" sx={{ color: theme?.colors?.primary, ml: 0.5 }} />
162
161
  ) : (
163
162
  <RefreshOutlinedIcon onClick={refreshProfile} />
@@ -21,7 +21,6 @@ export default function UserSessionInfo({ user, sessionUser }: { readonly user:
21
21
  size={40}
22
22
  variant="circle"
23
23
  shape="circle"
24
- // @ts-expect-error
25
24
  src={sessionUser.avatar}
26
25
  did={sessionUser.did}
27
26
  sx={{ flexShrink: 0 }}
@@ -11,11 +11,12 @@ import { getVisitorId } from '@arcblock/ux/lib/Util';
11
11
  import { useConfirm } from '@arcblock/ux/lib/Dialog';
12
12
  import pAll from 'p-all';
13
13
  import { Box, Button, Tooltip, Typography } from '@mui/material';
14
- import { ReactElement } from 'react';
14
+ import { ReactElement, useContext } from 'react';
15
15
  import { UserSession } from '@blocklet/js-sdk';
16
+ import { SessionContext } from '@arcblock/did-connect/lib/Session';
16
17
 
17
18
  import UserSessionInfo from './user-session-info';
18
- import { User } from '../../@types';
19
+ import { User, SessionContext as TSessionContext } from '../../@types';
19
20
  import { client } from '../../libs/client';
20
21
  import { translations } from '../libs/locales';
21
22
  import { batchIp2Region } from '../libs/utils';
@@ -40,6 +41,7 @@ export default function UserSessions({
40
41
  readonly showAction?: boolean;
41
42
  readonly showUser?: boolean;
42
43
  }) {
44
+ const { session } = useContext<TSessionContext>(SessionContext);
43
45
  const currentVisitorId = getVisitorId();
44
46
  const { locale } = useLocaleContext();
45
47
  const { confirmApi, confirmHolder } = useConfirm();
@@ -47,11 +49,12 @@ export default function UserSessions({
47
49
  return translate(translations, key, locale, 'en', data);
48
50
  });
49
51
  const getData: () => Promise<(UserSession & { ipRegion?: string })[]> = useMemoizedFn(async () => {
50
- let data = user?.userSessions as (UserSession & { ipRegion?: string })[];
51
- if (!data) {
52
- data = await client.userSession.getUserSessions({ did: user.did });
53
- }
52
+ let data = (user?.userSessions || []) as (UserSession & { ipRegion?: string })[];
54
53
  try {
54
+ if (!data && session.user) {
55
+ data = await client.userSession.getUserSessionsByMyself();
56
+ }
57
+ // FIXME: @zhanghan 优化获取 IP 信息的处理逻辑
55
58
  const ipIndexList = data?.map((x, index) => [index, x.lastLoginIp] as [number, string]).filter((x) => !!x[1]);
56
59
  const ipList = ipIndexList?.map((x) => x[1]);
57
60
  const result = await batchIp2Region(ipList);
@@ -209,7 +212,6 @@ export default function UserSessions({
209
212
  customBodyRenderLite: (rawIndex: number) => {
210
213
  const x = safeData[rawIndex];
211
214
  return x.createdAt ? (
212
- // @ts-expect-error
213
215
  <RelativeTime value={x.createdAt} relativeRange={3 * 86400 * 1000} locale={locale} />
214
216
  ) : (
215
217
  t('unknown')
@@ -226,7 +228,6 @@ export default function UserSessions({
226
228
  return x.status === 'expired' ? (
227
229
  t('expired')
228
230
  ) : (
229
- // @ts-expect-error
230
231
  <RelativeTime value={x.updatedAt} relativeRange={3 * 86400 * 1000} locale={locale} />
231
232
  );
232
233
  },
@@ -299,7 +300,9 @@ export default function UserSessions({
299
300
  <Datatable
300
301
  locale={locale}
301
302
  data={safeData}
303
+ // @ts-expect-error
302
304
  columns={columns}
305
+ // @ts-expect-error
303
306
  customButtons={customButtons}
304
307
  options={tableOptions}
305
308
  loading={pageState.loading}
@@ -1,3 +0,0 @@
1
- import axios from 'axios';
2
- declare const api: import("axios").AxiosInstance;
3
- export { axios, api };
@@ -1,4 +0,0 @@
1
- import axios from "axios";
2
- axios.defaults.timeout = 10 * 1e3;
3
- const api = axios.create();
4
- export { axios, api };
@@ -1,7 +0,0 @@
1
- import axios from 'axios';
2
-
3
- axios.defaults.timeout = 10 * 1000; // 超时时间设为10s
4
-
5
- const api = axios.create();
6
-
7
- export { axios, api };