@blocklet/ui-react 3.1.26 → 3.1.28

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.
Files changed (35) hide show
  1. package/lib/@types/index.d.ts +1 -1
  2. package/lib/Footer/links.js +26 -33
  3. package/lib/UserCenter/components/fallback.d.ts +8 -0
  4. package/lib/UserCenter/components/fallback.js +21 -0
  5. package/lib/UserCenter/components/user-center.js +205 -200
  6. package/lib/UserCenter/components/user-info/social-actions/chat.d.ts +5 -0
  7. package/lib/UserCenter/components/user-info/social-actions/chat.js +24 -0
  8. package/lib/UserCenter/components/user-info/social-actions/follow.d.ts +2 -0
  9. package/lib/UserCenter/components/user-info/social-actions/follow.js +19 -0
  10. package/lib/UserCenter/components/user-info/social-actions/index.d.ts +5 -0
  11. package/lib/UserCenter/components/user-info/social-actions/index.js +13 -0
  12. package/lib/UserCenter/components/user-info/user-basic-info.js +37 -35
  13. package/lib/UserCenter/libs/locales.d.ts +14 -0
  14. package/lib/UserCenter/libs/locales.js +16 -2
  15. package/lib/blocklets.js +56 -54
  16. package/lib/contexts/user-followers.d.ts +13 -0
  17. package/lib/contexts/user-followers.js +40 -0
  18. package/lib/hooks/use-follow.d.ts +12 -0
  19. package/lib/hooks/use-follow.js +47 -0
  20. package/lib/utils.d.ts +1 -0
  21. package/lib/utils.js +37 -36
  22. package/package.json +6 -6
  23. package/src/@types/index.ts +1 -1
  24. package/src/Footer/links.jsx +10 -7
  25. package/src/UserCenter/components/fallback.tsx +51 -0
  26. package/src/UserCenter/components/user-center.tsx +22 -12
  27. package/src/UserCenter/components/user-info/social-actions/chat.tsx +42 -0
  28. package/src/UserCenter/components/user-info/social-actions/follow.tsx +30 -0
  29. package/src/UserCenter/components/user-info/social-actions/index.tsx +17 -0
  30. package/src/UserCenter/components/user-info/user-basic-info.tsx +6 -0
  31. package/src/UserCenter/libs/locales.ts +14 -0
  32. package/src/blocklets.js +5 -1
  33. package/src/contexts/user-followers.tsx +54 -0
  34. package/src/hooks/use-follow.tsx +74 -0
  35. package/src/utils.js +5 -0
@@ -0,0 +1,19 @@
1
+ import { jsxs as m, jsx as r } from "react/jsx-runtime";
2
+ import { Button as s } from "@mui/material";
3
+ import { useMemoizedFn as p } from "ahooks";
4
+ import { translate as a } from "@arcblock/ux/lib/Locale/util";
5
+ import { useLocaleContext as c } from "@arcblock/ux/lib/Locale/context";
6
+ import u from "@mui/icons-material/Notifications";
7
+ import x from "@mui/icons-material/NotificationsOff";
8
+ import { translations as w } from "../../../libs/locales.js";
9
+ import { useUserFollowersContext as d } from "../../../../contexts/user-followers.js";
10
+ function R() {
11
+ const { locale: i } = c(), t = p((l, f = {}) => a(w, l, i, "en", f)), { followed: o, followUser: n, unfollowUser: e } = d();
12
+ return /* @__PURE__ */ m(s, { variant: "contained", onClick: () => o ? e() : n(), fullWidth: !0, children: [
13
+ o ? /* @__PURE__ */ r(x, { sx: { fontSize: "14px", marginRight: "4px" } }) : /* @__PURE__ */ r(u, { sx: { fontSize: "14px", marginRight: "4px" } }),
14
+ t(o ? "profile.unfollow" : "profile.follow")
15
+ ] });
16
+ }
17
+ export {
18
+ R as default
19
+ };
@@ -0,0 +1,5 @@
1
+ import { User } from '../../../../@types';
2
+ declare function SocialActions({ user }: {
3
+ user: User;
4
+ }): import("react/jsx-runtime").JSX.Element;
5
+ export default SocialActions;
@@ -0,0 +1,13 @@
1
+ import { jsxs as t, jsx as o } from "react/jsx-runtime";
2
+ import { Box as i } from "@mui/material";
3
+ import m from "./chat.js";
4
+ import f from "./follow.js";
5
+ function x({ user: r }) {
6
+ return /* @__PURE__ */ t(i, { sx: { display: "flex", gap: 1 }, children: [
7
+ /* @__PURE__ */ o(m, { user: r }),
8
+ /* @__PURE__ */ o(f, {})
9
+ ] });
10
+ }
11
+ export {
12
+ x as default
13
+ };
@@ -1,12 +1,12 @@
1
1
  import { jsxs as c, jsx as r, Fragment as E } from "react/jsx-runtime";
2
- import { Box as l, Typography as y, Divider as B, IconButton as N, Collapse as T } from "@mui/material";
2
+ import { Box as l, Typography as S, Divider as B, IconButton as N, Collapse as T } from "@mui/material";
3
3
  import F from "@arcblock/ux/lib/Avatar";
4
4
  import K from "@arcblock/ux/lib/DID";
5
5
  import { useMemoizedFn as W } from "ahooks";
6
6
  import { translate as O } from "@arcblock/ux/lib/Locale/util";
7
7
  import { useLocaleContext as Q } from "@arcblock/ux/lib/Locale/context";
8
8
  import V from "lodash/noop";
9
- import { useState as S, useEffect as U } from "react";
9
+ import { useState as U, useEffect as y } from "react";
10
10
  import C from "@arcblock/ux/lib/Toast";
11
11
  import { parseURL as Y, joinURL as $ } from "ufo";
12
12
  import { KeyboardArrowUp as q, KeyboardArrowDown as G } from "@mui/icons-material";
@@ -18,29 +18,30 @@ import P from "./metadata.js";
18
18
  import M from "./user-status.js";
19
19
  import tt from "./user-info.js";
20
20
  import { client as j } from "../../../libs/client.js";
21
- function St({
21
+ import rt from "./social-actions/index.js";
22
+ function Ct({
22
23
  user: t,
23
- isMyself: a = !0,
24
+ isMyself: e = !0,
24
25
  showFullDid: f = !0,
25
26
  switchPassport: I,
26
27
  switchProfile: R,
27
- isMobile: o = !1,
28
+ isMobile: a = !1,
28
29
  onlyProfile: s = !1,
29
30
  refreshProfile: u,
30
31
  ...m
31
32
  }) {
32
- const { locale: x } = Q(), [h, g] = S(void 0), w = W((n, e = {}) => O(H, n, x, "en", e)), [d, v] = S(!o || s);
33
- U(() => {
33
+ const { locale: x } = Q(), [h, g] = U(void 0), w = W((n, o = {}) => O(H, n, x, "en", o)), [d, v] = U(!a || s);
34
+ y(() => {
34
35
  g(t?.metadata?.status);
35
- }, [t]), U(() => {
36
- v(!o || s);
37
- }, [o, s]);
36
+ }, [t]), y(() => {
37
+ v(!a || s);
38
+ }, [a, s]);
38
39
  const A = async (n) => {
39
- if (a)
40
+ if (e)
40
41
  try {
41
42
  if (n) {
42
- const e = X(n);
43
- n.dateRange = e.length > 0 ? e : h?.dateRange ?? [];
43
+ const o = X(n);
44
+ n.dateRange = o.length > 0 ? o : h?.dateRange ?? [];
44
45
  }
45
46
  g(n), await j.user.saveProfile({
46
47
  // @ts-ignore
@@ -49,8 +50,8 @@ function St({
49
50
  status: n || {}
50
51
  }
51
52
  }), u();
52
- } catch (e) {
53
- console.error(e), C.error(z(e));
53
+ } catch (o) {
54
+ console.error(o), C.error(z(o));
54
55
  }
55
56
  }, b = () => {
56
57
  v(!d);
@@ -58,11 +59,11 @@ function St({
58
59
  if (!t)
59
60
  return null;
60
61
  const D = async (n) => {
61
- if (!a)
62
+ if (!e)
62
63
  return;
63
- const { metadata: e, address: L } = n;
64
+ const { metadata: o, address: L } = n;
64
65
  try {
65
- const p = e?.links?.map((i) => {
66
+ const p = o?.links?.map((i) => {
66
67
  if (!i.url || !Z(i.url)) return null;
67
68
  try {
68
69
  return Y(i.url).protocol || (i.url = $("https://", i.url)), i;
@@ -70,7 +71,7 @@ function St({
70
71
  return console.error("Invalid URL:", i.url), null;
71
72
  }
72
73
  }).filter((i) => !!i) || [];
73
- e.links = p, await j.user.saveProfile({ metadata: e, address: L }), u();
74
+ o.links = p, await j.user.saveProfile({ metadata: o, address: L }), u();
74
75
  } catch (p) {
75
76
  console.error(p), C.error(z(p));
76
77
  }
@@ -90,7 +91,7 @@ function St({
90
91
  className: "user-info",
91
92
  sx: {
92
93
  display: "flex",
93
- flexDirection: o ? "row" : "column",
94
+ flexDirection: a ? "row" : "column",
94
95
  gap: 2
95
96
  },
96
97
  children: [
@@ -110,7 +111,7 @@ function St({
110
111
  {
111
112
  src: t?.avatar,
112
113
  did: t?.did,
113
- size: m.size || (o ? 64 : 100),
114
+ size: m.size || (a ? 64 : 100),
114
115
  variant: "circle",
115
116
  shape: "circle",
116
117
  sx: {
@@ -119,7 +120,7 @@ function St({
119
120
  position: "relative",
120
121
  overflow: "hidden",
121
122
  flexShrink: 0,
122
- ...a ? {
123
+ ...e ? {
123
124
  cursor: "pointer",
124
125
  "&::after": {
125
126
  content: `"${w("switchProfile")}"`,
@@ -137,15 +138,15 @@ function St({
137
138
  }
138
139
  } : {}
139
140
  },
140
- onClick: a ? R : V
141
+ onClick: e ? R : V
141
142
  }
142
143
  ),
143
144
  /* @__PURE__ */ r(
144
145
  M,
145
146
  {
146
- isMobile: o,
147
- size: m.size || (o ? 64 : 100),
148
- isMyself: a,
147
+ isMobile: a,
148
+ size: m.size || (a ? 64 : 100),
149
+ isMyself: e,
149
150
  timezone: t?.metadata?.timezone || J,
150
151
  status: h,
151
152
  onChange: A
@@ -163,7 +164,7 @@ function St({
163
164
  },
164
165
  children: [
165
166
  /* @__PURE__ */ c(
166
- y,
167
+ S,
167
168
  {
168
169
  variant: "h6",
169
170
  component: "div",
@@ -188,7 +189,7 @@ function St({
188
189
  children: t?.fullName
189
190
  }
190
191
  ),
191
- a ? /* @__PURE__ */ r(_, { user: t, switchPassport: I }) : null
192
+ e ? /* @__PURE__ */ r(_, { user: t, switchPassport: I }) : null
192
193
  ]
193
194
  }
194
195
  ),
@@ -199,10 +200,11 @@ function St({
199
200
  ]
200
201
  }
201
202
  ),
202
- /* @__PURE__ */ r(P, { isMobile: o, isMyself: a, user: t, onSave: D }),
203
- a ? /* @__PURE__ */ c(E, { children: [
204
- /* @__PURE__ */ r(B, { sx: { my: o ? 1 : 3 } }),
205
- o && !s ? /* @__PURE__ */ r(
203
+ e ? null : /* @__PURE__ */ r(l, { sx: { mt: 2 }, children: /* @__PURE__ */ r(rt, { user: t }) }),
204
+ /* @__PURE__ */ r(P, { isMobile: a, isMyself: e, user: t, onSave: D }),
205
+ e ? /* @__PURE__ */ c(E, { children: [
206
+ /* @__PURE__ */ r(B, { sx: { my: a ? 1 : 3 } }),
207
+ a && !s ? /* @__PURE__ */ r(
206
208
  l,
207
209
  {
208
210
  sx: {
@@ -229,7 +231,7 @@ function St({
229
231
  ) : null,
230
232
  /* @__PURE__ */ c(T, { in: d, timeout: "auto", children: [
231
233
  /* @__PURE__ */ r(
232
- y,
234
+ S,
233
235
  {
234
236
  component: "p",
235
237
  sx: {
@@ -240,7 +242,7 @@ function St({
240
242
  children: w("profile.justForYou")
241
243
  }
242
244
  ),
243
- /* @__PURE__ */ r(tt, { user: t, isMySelf: a })
245
+ /* @__PURE__ */ r(tt, { user: t, isMySelf: e })
244
246
  ] })
245
247
  ] }) : null
246
248
  ]
@@ -248,5 +250,5 @@ function St({
248
250
  );
249
251
  }
250
252
  export {
251
- St as default
253
+ Ct as default
252
254
  };
@@ -25,10 +25,12 @@ export declare const translations: {
25
25
  emptyField: string;
26
26
  emptyContent: string;
27
27
  underProtected: string;
28
+ followersOnly: string;
28
29
  noUserFound: string;
29
30
  notificationManagement: string;
30
31
  privacyManagement: string;
31
32
  storageManagement: string;
33
+ userFollowers: string;
32
34
  webhook: {
33
35
  url: string;
34
36
  slack: string;
@@ -159,6 +161,11 @@ export declare const translations: {
159
161
  invalidPostalCode: string;
160
162
  };
161
163
  maxLinkCount: string;
164
+ chat: string;
165
+ follow: string;
166
+ unfollow: string;
167
+ follow_success: string;
168
+ unfollow_success: string;
162
169
  };
163
170
  destroyMyself: {
164
171
  title: string;
@@ -201,8 +208,10 @@ export declare const translations: {
201
208
  notificationManagement: string;
202
209
  privacyManagement: string;
203
210
  storageManagement: string;
211
+ userFollowers: string;
204
212
  emptyContent: string;
205
213
  underProtected: string;
214
+ followersOnly: string;
206
215
  noUserFound: string;
207
216
  webhook: {
208
217
  url: string;
@@ -335,6 +344,11 @@ export declare const translations: {
335
344
  invalidPostalCode: string;
336
345
  };
337
346
  maxLinkCount: string;
347
+ chat: string;
348
+ follow: string;
349
+ unfollow: string;
350
+ follow_success: string;
351
+ unfollow_success: string;
338
352
  };
339
353
  destroyMyself: {
340
354
  title: string;
@@ -25,10 +25,12 @@ const e = {
25
25
  emptyField: "未填写",
26
26
  emptyContent: "暂无内容",
27
27
  underProtected: "用户已设置隐私保护",
28
+ followersOnly: "用户已设置仅粉丝可见,关注用户后可查看",
28
29
  noUserFound: "未找到指定的用户",
29
30
  notificationManagement: "通知管理",
30
31
  privacyManagement: "隐私管理",
31
32
  storageManagement: "DID Spaces",
33
+ userFollowers: "关注 & 粉丝",
32
34
  webhook: {
33
35
  url: "自定义URL",
34
36
  slack: "Slack"
@@ -158,7 +160,12 @@ const e = {
158
160
  postalCode: "邮政编码",
159
161
  invalidPostalCode: "邮政编码格式不正确"
160
162
  },
161
- maxLinkCount: "最多可添加 {count} 个社交链接"
163
+ maxLinkCount: "最多可添加 {count} 个社交链接",
164
+ chat: "聊天",
165
+ follow: "关注",
166
+ unfollow: "取消关注",
167
+ follow_success: "关注成功",
168
+ unfollow_success: "取消关注成功"
162
169
  },
163
170
  destroyMyself: {
164
171
  title: "删除账户",
@@ -201,8 +208,10 @@ const e = {
201
208
  notificationManagement: "Notifications",
202
209
  privacyManagement: "Privacy",
203
210
  storageManagement: "DID Spaces",
211
+ userFollowers: "Following & Followers",
204
212
  emptyContent: "Empty",
205
213
  underProtected: "This page has protected privacy",
214
+ followersOnly: "This page is only visible to followers, follow the user to view",
206
215
  noUserFound: "No user found",
207
216
  webhook: {
208
217
  url: "Custom url",
@@ -334,7 +343,12 @@ const e = {
334
343
  postalCode: "Postal Code",
335
344
  invalidPostalCode: "Postal code is invalid"
336
345
  },
337
- maxLinkCount: "Up to {count} social links can be added"
346
+ maxLinkCount: "Up to {count} social links can be added",
347
+ chat: "Chat",
348
+ follow: "Follow",
349
+ unfollow: "Unfollow",
350
+ follow_success: "Follow successfully",
351
+ unfollow_success: "Unfollow successfully"
338
352
  },
339
353
  destroyMyself: {
340
354
  title: "Delete Account",
package/lib/blocklets.js CHANGED
@@ -1,48 +1,50 @@
1
- import { mapRecursive as s, filterRecursive as a, isUrl as f } from "./utils.js";
2
- const g = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || "/", i = (o) => {
3
- const r = { ...o }, e = o?.background;
4
- return typeof e == "string" ? r.background = { header: e, footer: e, default: e } : e && typeof e == "object" && (r.background = {
5
- header: e.header || e.default,
6
- footer: e.footer || e.default,
7
- default: e.default
1
+ import { mapRecursive as s, filterRecursive as a, isUrl as f, isMailProtocol as i } from "./utils.js";
2
+ const p = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || "/", c = (e) => {
3
+ const r = { ...e }, t = e?.background;
4
+ return typeof t == "string" ? r.background = { header: t, footer: t, default: t } : t && typeof t == "object" && (r.background = {
5
+ header: t.header || t.default,
6
+ footer: t.footer || t.default,
7
+ default: t.default
8
8
  }), r;
9
- }, c = (o, r = "en") => {
10
- if (typeof o == "string") {
11
- if (f(o)) {
12
- const t = new URL(o);
13
- return t.searchParams.set("locale", r), t.href;
9
+ }, u = (e, r = "en") => {
10
+ if (typeof e == "string") {
11
+ if (f(e)) {
12
+ const o = new URL(e);
13
+ return o.searchParams.set("locale", r), o.href;
14
14
  }
15
- const e = new URL(o, window.location.origin);
16
- return e.searchParams.set("locale", r), e.pathname + e.search;
15
+ if (i(e))
16
+ return e;
17
+ const t = new URL(e, window.location.origin);
18
+ return t.searchParams.set("locale", r), t.pathname + t.search;
17
19
  }
18
- return typeof o == "object" ? o[r] || o?.en || o?.zh : o;
19
- }, p = (o, r = "en") => {
20
- if (!o?.length)
21
- return o;
22
- const e = (t, n) => t && typeof t == "object" ? t[n] || t?.en || t?.zh : t;
20
+ return typeof e == "object" ? e[r] || e?.en || e?.zh : e;
21
+ }, b = (e, r = "en") => {
22
+ if (!e?.length)
23
+ return e;
24
+ const t = (o, n) => o && typeof o == "object" ? o[n] || o?.en || o?.zh : o;
23
25
  return s(
24
- o,
25
- (t) => ({
26
- ...t,
27
- title: e(t.title, r),
28
- description: e(t.description, r),
26
+ e,
27
+ (o) => ({
28
+ ...o,
29
+ title: t(o.title, r),
30
+ description: t(o.description, r),
29
31
  // 仅对叶结点进行处理
30
- link: t.items?.length ? t.link : c(t.link, r),
31
- _rawLink: t.link
32
+ link: o.items?.length ? o.link : u(o.link, r),
33
+ _rawLink: o.link
32
34
  }),
33
35
  "items"
34
36
  );
35
- }, u = (o) => s(
36
- o,
37
+ }, l = (e) => s(
38
+ e,
37
39
  (r) => r.role ? {
38
40
  ...r,
39
41
  role: Array.isArray(r.role) ? r.role : [r.role]
40
42
  } : r,
41
43
  "items"
42
- ), l = (o) => {
43
- if (!o?.length)
44
+ ), d = (e) => {
45
+ if (!e?.length)
44
46
  return null;
45
- const r = u(o), e = {
47
+ const r = l(e), t = {
46
48
  header: [],
47
49
  footer: [],
48
50
  // 对应 footer social media
@@ -55,32 +57,32 @@ const g = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || "/", i =
55
57
  sessionManager: [],
56
58
  userCenter: []
57
59
  };
58
- return r.forEach((t) => {
59
- t.section ? Array.isArray(t.section) ? t.section.forEach((n) => {
60
- e[n]?.push(t);
61
- }) : typeof t.section == "string" && e[t.section]?.push(t) : e.header.push(t);
62
- }), e;
63
- }, b = (o) => {
64
- if (!o)
60
+ return r.forEach((o) => {
61
+ o.section ? Array.isArray(o.section) ? o.section.forEach((n) => {
62
+ t[n]?.push(o);
63
+ }) : typeof o.section == "string" && t[o.section]?.push(o) : t.header.push(o);
64
+ }), t;
65
+ }, y = (e) => {
66
+ if (!e)
65
67
  return null;
66
- const r = { ...o };
67
- return r.theme = i(r.theme), r.navigation = l(d(r.navigation)), r;
68
- }, d = (o = []) => a(o, (r, e) => !!r.link || e.filteredChildren?.length, "items"), y = (o, r) => a(
69
- o,
70
- (e, t) => {
71
- const n = !e.role || r && (e.role.includes(r) || e.role.includes("guest"));
72
- return t.isLeaf ? n : n && t.filteredChildren?.length;
68
+ const r = { ...e };
69
+ return r.theme = c(r.theme), r.navigation = d(h(r.navigation)), r;
70
+ }, h = (e = []) => a(e, (r, t) => !!r.link || t.filteredChildren?.length, "items"), w = (e, r) => a(
71
+ e,
72
+ (t, o) => {
73
+ const n = !t.role || r && (t.role.includes(r) || t.role.includes("guest"));
74
+ return o.isLeaf ? n : n && o.filteredChildren?.length;
73
75
  },
74
76
  "items"
75
77
  );
76
78
  export {
77
- y as filterNavByRole,
78
- d as filterValidNavItems,
79
- b as formatBlockletInfo,
80
- u as formatNavigation,
81
- i as formatTheme,
82
- c as getLink,
83
- p as getLocalizedNavigation,
84
- l as parseNavigation,
85
- g as publicPath
79
+ w as filterNavByRole,
80
+ h as filterValidNavItems,
81
+ y as formatBlockletInfo,
82
+ l as formatNavigation,
83
+ c as formatTheme,
84
+ u as getLink,
85
+ b as getLocalizedNavigation,
86
+ d as parseNavigation,
87
+ p as publicPath
86
88
  };
@@ -0,0 +1,13 @@
1
+ declare const UserFollowersContext: import('react').Context<UserFollowersContextType>;
2
+ type UserFollowersContextType = {
3
+ followed: boolean;
4
+ followUser: () => void;
5
+ unfollowUser: () => void;
6
+ };
7
+ declare function UserFollowersProvider({ isMySelf, userDid, children, }: {
8
+ children: React.ReactNode;
9
+ isMySelf: boolean;
10
+ userDid: string;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ declare function useUserFollowersContext(): UserFollowersContextType;
13
+ export { UserFollowersContext, useUserFollowersContext, UserFollowersProvider };
@@ -0,0 +1,40 @@
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import { createContext as w, useContext as a } from "react";
3
+ import { translate as p } from "@arcblock/ux/lib/Locale/util";
4
+ import { useMemoizedFn as x } from "ahooks";
5
+ import { useLocaleContext as U } from "@arcblock/ux/lib/Locale/context";
6
+ import d from "../hooks/use-follow.js";
7
+ import { translations as C } from "../UserCenter/libs/locales.js";
8
+ const e = w({
9
+ followed: !1,
10
+ followUser: () => {
11
+ },
12
+ unfollowUser: () => {
13
+ }
14
+ }), { Provider: F } = e;
15
+ function g({
16
+ isMySelf: o,
17
+ userDid: r,
18
+ children: t
19
+ }) {
20
+ const { locale: s } = U(), l = x((i, u = {}) => p(C, i, s, "en", u)), { followed: n, followUser: f, unfollowUser: m } = d({ userDid: r, t: l, isMySelf: o });
21
+ return /* @__PURE__ */ c(
22
+ F,
23
+ {
24
+ value: {
25
+ followed: n,
26
+ followUser: f,
27
+ unfollowUser: m
28
+ },
29
+ children: t
30
+ }
31
+ );
32
+ }
33
+ function h() {
34
+ return a(e);
35
+ }
36
+ export {
37
+ e as UserFollowersContext,
38
+ g as UserFollowersProvider,
39
+ h as useUserFollowersContext
40
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 登录用户与当前用户(userDid)的关注关系
3
+ */
4
+ export default function useFollow({ userDid, t, isMySelf, }: {
5
+ userDid: string;
6
+ t: (k: string) => string;
7
+ isMySelf: boolean;
8
+ }): {
9
+ followed: boolean;
10
+ followUser: (this: unknown, followUserDid?: string | undefined) => Promise<void>;
11
+ unfollowUser: (this: unknown, unfollowUserDid?: string | undefined) => Promise<void>;
12
+ };
@@ -0,0 +1,47 @@
1
+ import { useState as p, useEffect as F } from "react";
2
+ import { useMemoizedFn as n } from "ahooks";
3
+ import c from "@arcblock/ux/lib/Toast";
4
+ import { client as l } from "../libs/client.js";
5
+ import { formatAxiosError as u } from "../UserCenter/libs/utils.js";
6
+ function E({
7
+ userDid: o,
8
+ t: a,
9
+ isMySelf: e
10
+ }) {
11
+ const [i, f] = p(!1), t = n(async () => {
12
+ try {
13
+ if (e) {
14
+ f(!0);
15
+ return;
16
+ }
17
+ const r = await l.user.isFollowingUser({ userDid: o });
18
+ f(r);
19
+ } catch (r) {
20
+ console.error(r);
21
+ }
22
+ }), m = n(async (r = o) => {
23
+ if (!(e && r === o))
24
+ try {
25
+ await l.user.followUser({ userDid: r }), c.success(a("profile.follow_success")), t();
26
+ } catch (s) {
27
+ console.error(s), c.error(u(s));
28
+ }
29
+ }), w = n(async (r = o) => {
30
+ if (!(e && r === o))
31
+ try {
32
+ await l.user.unfollowUser({ userDid: r }), c.success(a("profile.unfollow_success")), t();
33
+ } catch (s) {
34
+ console.error(s), c.error(u(s));
35
+ }
36
+ });
37
+ return F(() => {
38
+ o && !e && t();
39
+ }, [t, o, e]), {
40
+ followed: i,
41
+ followUser: m,
42
+ unfollowUser: w
43
+ };
44
+ }
45
+ export {
46
+ E as default
47
+ };
package/lib/utils.d.ts CHANGED
@@ -3,6 +3,7 @@ export function flatRecursive(array: any, childrenKey?: string): any[];
3
3
  export function countRecursive(array: any, childrenKey?: string): number;
4
4
  export function filterRecursive(array: any, predicate: any, childrenKey?: string): any;
5
5
  export function isUrl(str: any): boolean;
6
+ export function isMailProtocol(str: any): boolean;
6
7
  export function isIconifyString(str: any): boolean;
7
8
  export function matchPath(path: any): any;
8
9
  export function matchPaths(paths?: any[]): number;