@arcblock/ux 3.1.47 → 3.1.49
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.
- package/lib/Config/config-provider.d.ts +1 -0
- package/lib/DIDConnect/auth-apps/switch-role.d.ts +1 -0
- package/lib/Locale/context.d.ts +1 -0
- package/lib/Locale/context.js +45 -45
- package/lib/OrgTransfer/index.d.ts +5 -0
- package/lib/OrgTransfer/index.js +38 -0
- package/lib/OrgTransfer/locales.d.ts +25 -0
- package/lib/OrgTransfer/locales.js +27 -0
- package/lib/OrgTransfer/selector.d.ts +2 -0
- package/lib/OrgTransfer/selector.js +174 -0
- package/lib/OrgTransfer/type.d.ts +28 -0
- package/lib/OrgTransfer/type.js +1 -0
- package/lib/UserCard/use-follow.d.ts +0 -2
- package/lib/UserCard/use-follow.js +35 -39
- package/lib/Util/client.d.ts +6 -0
- package/lib/Util/client.js +7 -0
- package/lib/Util/index.d.ts +2 -0
- package/lib/Util/index.js +58 -54
- package/lib/package.json.js +1 -1
- package/package.json +7 -7
- package/src/DIDConnect/auth-apps/switch-role.tsx +1 -1
- package/src/Locale/context.tsx +9 -3
- package/src/OrgTransfer/index.tsx +53 -0
- package/src/OrgTransfer/locales.ts +25 -0
- package/src/OrgTransfer/selector.tsx +249 -0
- package/src/OrgTransfer/type.ts +31 -0
- package/src/UserCard/use-follow.tsx +1 -10
- package/src/Util/client.ts +9 -0
- package/src/Util/index.ts +11 -0
|
@@ -15,6 +15,7 @@ export declare function useConfig(): {
|
|
|
15
15
|
changeMode: (mode: import('@mui/material').PaletteMode) => void;
|
|
16
16
|
prefer?: import('../Theme').Prefer;
|
|
17
17
|
locale: import('../type').Locale;
|
|
18
|
+
defaultLocale: import('../type').Locale;
|
|
18
19
|
changeLocale: (locale: import('../type').Locale) => void;
|
|
19
20
|
t: (key: string, data?: Record<string, any>) => string;
|
|
20
21
|
languages: {
|
package/lib/Locale/context.d.ts
CHANGED
package/lib/Locale/context.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { translate as
|
|
7
|
-
import { getCookieOptions as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as k, use as A, useState as h, useRef as R, useEffect as b, useCallback as j } from "react";
|
|
3
|
+
import S from "lodash/get";
|
|
4
|
+
import l from "js-cookie";
|
|
5
|
+
import U from "./browser-lang.js";
|
|
6
|
+
import { translate as D } from "./util.js";
|
|
7
|
+
import { getCookieOptions as E, resolveRootDomain as F } from "../Util/index.js";
|
|
8
|
+
const i = "nf_lang", O = (e, o = window.location.href) => {
|
|
9
9
|
const t = new URL(o).searchParams.get("locale");
|
|
10
10
|
return e.find((c) => c.code === t) ? t : null;
|
|
11
|
-
},
|
|
11
|
+
}, z = (e, o = window.location.href) => {
|
|
12
12
|
const t = new URL(o);
|
|
13
13
|
t.searchParams.has("locale") && (t.searchParams.set("locale", e), window.history.replaceState({}, "", t.href));
|
|
14
|
-
},
|
|
14
|
+
}, g = (e = []) => {
|
|
15
15
|
const o = {
|
|
16
16
|
languages: e.map((t) => t.code),
|
|
17
17
|
// 取 languages 首个元素的 code 值, 如果不存在则取 'en'
|
|
18
18
|
fallback: e?.[0]?.code || "en"
|
|
19
19
|
};
|
|
20
|
-
return
|
|
21
|
-
},
|
|
22
|
-
const o =
|
|
20
|
+
return O(e) || l.get(i) || U(o);
|
|
21
|
+
}, N = (e) => {
|
|
22
|
+
const o = E();
|
|
23
23
|
if (!o.domain) {
|
|
24
|
-
const t =
|
|
25
|
-
t &&
|
|
24
|
+
const t = F();
|
|
25
|
+
t && l.remove(i, { path: o.path || "/", domain: t });
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
const o =
|
|
27
|
+
l.set(i, e, o), z(e);
|
|
28
|
+
}, _ = (e) => {
|
|
29
|
+
const o = S(window, "blocklet.languages");
|
|
30
30
|
return Array.isArray(o) && o.length ? o : Array.isArray(e) && e.length ? e : [
|
|
31
31
|
{ code: "en", name: "English" },
|
|
32
32
|
{ code: "zh", name: "简体中文" }
|
|
33
33
|
];
|
|
34
|
-
},
|
|
35
|
-
function
|
|
34
|
+
}, p = k(null), { Provider: q, Consumer: Q } = p;
|
|
35
|
+
function T({
|
|
36
36
|
children: e,
|
|
37
37
|
locale: o = void 0,
|
|
38
|
-
fallbackLocale: t =
|
|
38
|
+
fallbackLocale: t = "en",
|
|
39
39
|
translations: c,
|
|
40
|
-
onLoadingTranslation:
|
|
41
|
-
languages:
|
|
42
|
-
...
|
|
40
|
+
onLoadingTranslation: L = void 0,
|
|
41
|
+
languages: P = [],
|
|
42
|
+
...C
|
|
43
43
|
}) {
|
|
44
|
-
const s =
|
|
45
|
-
let [n, v] = h(o ||
|
|
46
|
-
const m =
|
|
47
|
-
v(r),
|
|
44
|
+
const s = _(P);
|
|
45
|
+
let [n, v] = h(o || g(s));
|
|
46
|
+
const m = s?.[0]?.code ?? t, u = R(m), [, w] = h(0), f = (r) => {
|
|
47
|
+
v(r), N(r);
|
|
48
48
|
};
|
|
49
|
-
if (
|
|
50
|
-
const r = o ||
|
|
51
|
-
r !== n &&
|
|
49
|
+
if (b(() => {
|
|
50
|
+
const r = o || g(s);
|
|
51
|
+
r !== n && f(r);
|
|
52
52
|
}, [o]), n && c[n] && typeof c[n] == "function") {
|
|
53
53
|
const r = n;
|
|
54
54
|
try {
|
|
55
55
|
Promise.resolve(c[r]()).then((a) => {
|
|
56
|
-
a && typeof a == "object" && (c[r] = a,
|
|
56
|
+
a && typeof a == "object" && (c[r] = a, w((d) => d > 999 ? 0 : d + 1));
|
|
57
57
|
});
|
|
58
58
|
} catch (a) {
|
|
59
59
|
console.error(a);
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
L?.(r, s), n = u.current;
|
|
62
62
|
} else
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
(r, a) =>
|
|
63
|
+
u.current = n;
|
|
64
|
+
const y = j(
|
|
65
|
+
(r, a) => D(c, r, n, t, a),
|
|
66
66
|
[c, n, t]
|
|
67
67
|
);
|
|
68
|
-
return /* @__PURE__ */
|
|
68
|
+
return /* @__PURE__ */ x(q, { value: { locale: n, changeLocale: f, t: y, languages: s, defaultLocale: m, ...C }, children: e });
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
70
|
+
function V() {
|
|
71
|
+
return A(p);
|
|
72
72
|
}
|
|
73
73
|
export {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
Q as LocaleConsumer,
|
|
75
|
+
p as LocaleContext,
|
|
76
|
+
T as LocaleProvider,
|
|
77
|
+
g as getLocale,
|
|
78
|
+
N as setLocale,
|
|
79
|
+
V as useLocaleContext
|
|
80
80
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsxs as d, Fragment as g, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as x, cloneElement as k } from "react";
|
|
3
|
+
import { Button as C } from "@mui/material";
|
|
4
|
+
import { useMemoizedFn as O } from "ahooks";
|
|
5
|
+
import h from "./selector.js";
|
|
6
|
+
import j from "./locales.js";
|
|
7
|
+
import { translate as F } from "../Locale/util.js";
|
|
8
|
+
function T({
|
|
9
|
+
org: e,
|
|
10
|
+
onSuccess: f,
|
|
11
|
+
resourceId: s,
|
|
12
|
+
buttonProps: n,
|
|
13
|
+
buttonText: l,
|
|
14
|
+
locale: t = "en",
|
|
15
|
+
dialogProps: c,
|
|
16
|
+
children: o
|
|
17
|
+
}) {
|
|
18
|
+
const a = O((u, p = {}) => F(j, u, t, "en", p)), r = x(null), m = () => {
|
|
19
|
+
r.current && r.current.open({ selectedOrg: e });
|
|
20
|
+
};
|
|
21
|
+
return /* @__PURE__ */ d(g, { children: [
|
|
22
|
+
o ? k(o, { ...n, onClick: m }) : /* @__PURE__ */ i(C, { ...n, onClick: m, children: l || a("transferOrg") }),
|
|
23
|
+
/* @__PURE__ */ i(
|
|
24
|
+
h,
|
|
25
|
+
{
|
|
26
|
+
locale: t,
|
|
27
|
+
org: e,
|
|
28
|
+
ref: r,
|
|
29
|
+
resourceId: s,
|
|
30
|
+
onSuccess: f,
|
|
31
|
+
dialogProps: c
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
T as default
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
en: {
|
|
3
|
+
transferOrg: string;
|
|
4
|
+
cancel: string;
|
|
5
|
+
confirm: string;
|
|
6
|
+
tranferSuccess: string;
|
|
7
|
+
placeholder: string;
|
|
8
|
+
loading: string;
|
|
9
|
+
noResults: string;
|
|
10
|
+
resourceIdRequired: string;
|
|
11
|
+
organizationSameAsCurrent: string;
|
|
12
|
+
};
|
|
13
|
+
zh: {
|
|
14
|
+
transferOrg: string;
|
|
15
|
+
cancel: string;
|
|
16
|
+
confirm: string;
|
|
17
|
+
tranferSuccess: string;
|
|
18
|
+
placeholder: string;
|
|
19
|
+
loading: string;
|
|
20
|
+
noResults: string;
|
|
21
|
+
resourceIdRequired: string;
|
|
22
|
+
organizationSameAsCurrent: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
en: {
|
|
3
|
+
transferOrg: "Transfer to Other Organization",
|
|
4
|
+
cancel: "Cancel",
|
|
5
|
+
confirm: "Confirm",
|
|
6
|
+
tranferSuccess: "Transfer success",
|
|
7
|
+
placeholder: "Select an organization to transfer",
|
|
8
|
+
loading: "Loading...",
|
|
9
|
+
noResults: "No More",
|
|
10
|
+
resourceIdRequired: "Please select the resource to transfer",
|
|
11
|
+
organizationSameAsCurrent: "The selected organization is the same as the current organization, please select other organizations"
|
|
12
|
+
},
|
|
13
|
+
zh: {
|
|
14
|
+
transferOrg: "转移至其他组织",
|
|
15
|
+
cancel: "取消",
|
|
16
|
+
confirm: "确认",
|
|
17
|
+
tranferSuccess: "转移成功",
|
|
18
|
+
placeholder: "请选择要转移的组织",
|
|
19
|
+
loading: "加载中...",
|
|
20
|
+
noResults: "没有更多了",
|
|
21
|
+
resourceIdRequired: "请选择要转移的资源",
|
|
22
|
+
organizationSameAsCurrent: "选择的组织与当前组织相同,请选择其他组织"
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
e as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { jsx as n, jsxs as i, Fragment as O } from "react/jsx-runtime";
|
|
2
|
+
import { useState as F, useImperativeHandle as _, createElement as y } from "react";
|
|
3
|
+
import { useMemoizedFn as p, useReactive as q, useDebounce as G, useInfiniteScroll as H } from "ahooks";
|
|
4
|
+
import { Box as l, Typography as a, Autocomplete as N, CircularProgress as b, TextField as Q, Button as v } from "@mui/material";
|
|
5
|
+
import w from "../Toast/index.js";
|
|
6
|
+
import Z from "../Dialog/dialog.js";
|
|
7
|
+
import "../Dialog/confirm.js";
|
|
8
|
+
import "lodash/noop";
|
|
9
|
+
import { OrgQueryType as J, client as T } from "../Util/client.js";
|
|
10
|
+
import { formatAxiosError as K } from "../Util/index.js";
|
|
11
|
+
import { translate as U } from "../Locale/util.js";
|
|
12
|
+
import X from "./locales.js";
|
|
13
|
+
const I = 20;
|
|
14
|
+
function ce({
|
|
15
|
+
ref: C,
|
|
16
|
+
org: g,
|
|
17
|
+
onSuccess: S,
|
|
18
|
+
resourceId: f,
|
|
19
|
+
locale: E = "en",
|
|
20
|
+
dialogProps: k
|
|
21
|
+
}) {
|
|
22
|
+
const o = p((e, r = {}) => U(X, e, E, "en", r)), [h, c] = F(""), t = q({
|
|
23
|
+
open: !1,
|
|
24
|
+
selectedOrg: null
|
|
25
|
+
}), x = G(h, { wait: 500 }), { data: A, loadMore: W, loadingMore: d, loading: u, reload: z } = H(
|
|
26
|
+
async (e) => {
|
|
27
|
+
if (!t.open) return { list: [], total: 0 };
|
|
28
|
+
const m = { page: e ? Math.ceil(e.list.length / I) + 1 : 1, pageSize: I, search: x, type: J.OWNED }, R = await T.user.getOrgs(m), { orgs: j = [], paging: B } = R || {};
|
|
29
|
+
return { list: j, total: B?.total || 0 };
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
reloadDeps: [x],
|
|
33
|
+
isNoMore: (e) => e?.list.length ? e.list.length >= e?.total : !0,
|
|
34
|
+
onError: (e) => {
|
|
35
|
+
console.error("Get orgs failed", e);
|
|
36
|
+
},
|
|
37
|
+
manual: !0
|
|
38
|
+
// 手动触发,在对话框打开时再加载
|
|
39
|
+
}
|
|
40
|
+
), s = p(() => {
|
|
41
|
+
t.open = !1, t.selectedOrg = null, c("");
|
|
42
|
+
}), M = p(async () => {
|
|
43
|
+
try {
|
|
44
|
+
if (!f)
|
|
45
|
+
throw new Error(o("resourceIdRequired"));
|
|
46
|
+
if (!t.selectedOrg)
|
|
47
|
+
throw new Error(o("placeholder"));
|
|
48
|
+
if (t.selectedOrg.id === g.id)
|
|
49
|
+
throw new Error(o("organizationSameAsCurrent"));
|
|
50
|
+
await T.user.migrateResourceToOrg({ form: g.id, to: t.selectedOrg.id, resourceId: f }), s(), S?.(t.selectedOrg), w.success(o("tranferSuccess"));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("Resource transfer failed", e), w.error(K(e));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
_(C, () => ({
|
|
56
|
+
open: (e = {}) => {
|
|
57
|
+
Object.assign(t, { open: !0, selectedOrg: null }, e), setTimeout(() => {
|
|
58
|
+
t.open && z();
|
|
59
|
+
}, 0);
|
|
60
|
+
},
|
|
61
|
+
close: s
|
|
62
|
+
}));
|
|
63
|
+
const D = A?.list || [], { placeholder: L = "", ...P } = k || {};
|
|
64
|
+
return /* @__PURE__ */ n(
|
|
65
|
+
Z,
|
|
66
|
+
{
|
|
67
|
+
title: o("transferOrg"),
|
|
68
|
+
fullWidth: !0,
|
|
69
|
+
maxWidth: "sm",
|
|
70
|
+
open: t.open,
|
|
71
|
+
onClose: s,
|
|
72
|
+
actions: /* @__PURE__ */ i(O, { children: [
|
|
73
|
+
/* @__PURE__ */ n(v, { onClick: s, color: "secondary", variant: "outlined", children: o("cancel") }),
|
|
74
|
+
/* @__PURE__ */ n(v, { onClick: M, color: "primary", variant: "contained", disabled: !t.selectedOrg, children: o("confirm") })
|
|
75
|
+
] }),
|
|
76
|
+
...P || {},
|
|
77
|
+
children: /* @__PURE__ */ i(l, { children: [
|
|
78
|
+
/* @__PURE__ */ n(a, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: L || o("placeholder") }),
|
|
79
|
+
/* @__PURE__ */ n(
|
|
80
|
+
N,
|
|
81
|
+
{
|
|
82
|
+
options: D,
|
|
83
|
+
getOptionLabel: (e) => e?.name || "",
|
|
84
|
+
isOptionEqualToValue: (e, r) => e?.id === r?.id,
|
|
85
|
+
value: t.selectedOrg,
|
|
86
|
+
onChange: (e, r) => {
|
|
87
|
+
if (r?.isLoadingItem && !d) {
|
|
88
|
+
W();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
r?.isLoadingItem || (t.selectedOrg = r, r && c(""));
|
|
92
|
+
},
|
|
93
|
+
inputValue: t.selectedOrg ? t.selectedOrg.name : h,
|
|
94
|
+
onInputChange: (e, r, m) => {
|
|
95
|
+
m === "input" && (t.selectedOrg && (t.selectedOrg = null), c(r));
|
|
96
|
+
},
|
|
97
|
+
loading: u,
|
|
98
|
+
loadingText: o("loading"),
|
|
99
|
+
noOptionsText: o(u ? "loading" : "noResults"),
|
|
100
|
+
renderInput: (e) => /* @__PURE__ */ n(
|
|
101
|
+
Q,
|
|
102
|
+
{
|
|
103
|
+
...e,
|
|
104
|
+
variant: "outlined",
|
|
105
|
+
fullWidth: !0,
|
|
106
|
+
InputProps: {
|
|
107
|
+
...e.InputProps,
|
|
108
|
+
endAdornment: /* @__PURE__ */ i(O, { children: [
|
|
109
|
+
u && /* @__PURE__ */ n(b, { color: "inherit", size: 20 }),
|
|
110
|
+
e.InputProps.endAdornment
|
|
111
|
+
] })
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
renderOption: (e, r) => r.isLoadingItem ? /* @__PURE__ */ y(l, { component: "li", ...e, key: r.id }, /* @__PURE__ */ i(
|
|
116
|
+
l,
|
|
117
|
+
{
|
|
118
|
+
sx: {
|
|
119
|
+
display: "flex",
|
|
120
|
+
alignItems: "center",
|
|
121
|
+
justifyContent: "center",
|
|
122
|
+
flex: 1,
|
|
123
|
+
py: 1,
|
|
124
|
+
color: "primary.main",
|
|
125
|
+
cursor: "pointer"
|
|
126
|
+
},
|
|
127
|
+
children: [
|
|
128
|
+
d && /* @__PURE__ */ n(b, { size: 16, sx: { mr: 1 } }),
|
|
129
|
+
/* @__PURE__ */ n(a, { variant: "body2", sx: { fontStyle: d ? "italic" : "normal" }, children: r.name })
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
)) : /* @__PURE__ */ y(l, { component: "li", ...e, key: r.id }, /* @__PURE__ */ i(l, { sx: { display: "flex", flexDirection: "column", flex: 1, minWidth: 0 }, children: [
|
|
133
|
+
/* @__PURE__ */ n(
|
|
134
|
+
a,
|
|
135
|
+
{
|
|
136
|
+
variant: "body1",
|
|
137
|
+
sx: {
|
|
138
|
+
overflow: "hidden",
|
|
139
|
+
textOverflow: "ellipsis",
|
|
140
|
+
whiteSpace: "nowrap"
|
|
141
|
+
},
|
|
142
|
+
children: r.name
|
|
143
|
+
}
|
|
144
|
+
),
|
|
145
|
+
r.description && /* @__PURE__ */ n(
|
|
146
|
+
a,
|
|
147
|
+
{
|
|
148
|
+
variant: "body2",
|
|
149
|
+
color: "text.secondary",
|
|
150
|
+
sx: {
|
|
151
|
+
display: "-webkit-box",
|
|
152
|
+
WebkitLineClamp: 3,
|
|
153
|
+
WebkitBoxOrient: "vertical",
|
|
154
|
+
overflow: "hidden",
|
|
155
|
+
textOverflow: "ellipsis"
|
|
156
|
+
},
|
|
157
|
+
children: r.description
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
] })),
|
|
161
|
+
sx: {
|
|
162
|
+
"& .MuiAutocomplete-listbox": {
|
|
163
|
+
maxHeight: 200
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
] })
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
ce as default
|
|
174
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import { ButtonProps } from '@mui/material';
|
|
3
|
+
import { default as Dialog } from '../Dialog';
|
|
4
|
+
export type Org = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
ownerDid: string;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
type DialogProps = ComponentProps<typeof Dialog> & {
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
};
|
|
14
|
+
export type OrgTransferSelectorProps = Omit<OrgTransferProps, 'children' | 'buttonProps' | 'buttonText'> & {
|
|
15
|
+
ref: React.RefObject<unknown | null>;
|
|
16
|
+
};
|
|
17
|
+
export interface OrgTransferProps {
|
|
18
|
+
resourceId: string;
|
|
19
|
+
onSuccess?: (org: Org) => void;
|
|
20
|
+
org?: Org;
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
buttonProps?: ButtonProps;
|
|
23
|
+
buttonText?: string;
|
|
24
|
+
dialogProps?: DialogProps;
|
|
25
|
+
locale?: string;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,67 +1,63 @@
|
|
|
1
|
-
import { useState as y, useMemo as
|
|
2
|
-
import { useMemoizedFn as
|
|
1
|
+
import { useState as y, useMemo as u, useEffect as F } from "react";
|
|
2
|
+
import { useMemoizedFn as f } from "ahooks";
|
|
3
3
|
import U from "lodash/isNil";
|
|
4
|
-
import { BlockletSDK as
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
user: r,
|
|
12
|
-
t,
|
|
13
|
-
isMySelf: n,
|
|
4
|
+
import { BlockletSDK as D } from "@blocklet/js-sdk";
|
|
5
|
+
import a from "../Toast/index.js";
|
|
6
|
+
import { formatAxiosError as d } from "../Util/index.js";
|
|
7
|
+
function K({
|
|
8
|
+
user: e,
|
|
9
|
+
t: w,
|
|
10
|
+
isMySelf: l,
|
|
14
11
|
visible: m
|
|
15
12
|
}) {
|
|
16
|
-
const [p, c] = y(!1),
|
|
13
|
+
const [p, c] = y(!1), t = u(() => e?.did, [e]), n = u(() => Object.prototype.hasOwnProperty.call(e, "isFollowing") && !U(e.isFollowing), [e]), r = u(() => {
|
|
17
14
|
let o = null;
|
|
18
15
|
try {
|
|
19
|
-
o = new
|
|
20
|
-
} catch (
|
|
21
|
-
console.error("Failed to initialize BlockletSDK:",
|
|
16
|
+
o = new D();
|
|
17
|
+
} catch (s) {
|
|
18
|
+
console.error("Failed to initialize BlockletSDK:", s), o = null;
|
|
22
19
|
}
|
|
23
20
|
return o;
|
|
24
|
-
}, []),
|
|
25
|
-
if (!
|
|
21
|
+
}, []), i = f(async () => {
|
|
22
|
+
if (!r) {
|
|
26
23
|
c(!1);
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
try {
|
|
30
|
-
if (
|
|
27
|
+
if (l) {
|
|
31
28
|
c(!0);
|
|
32
29
|
return;
|
|
33
30
|
}
|
|
34
|
-
const o = await
|
|
31
|
+
const o = await r.user.isFollowingUser({ userDid: t });
|
|
35
32
|
c(o);
|
|
36
33
|
} catch (o) {
|
|
37
34
|
console.error(o);
|
|
38
35
|
}
|
|
39
|
-
}),
|
|
40
|
-
if (!(!
|
|
36
|
+
}), h = f(async (o = t) => {
|
|
37
|
+
if (!(!r || l && o === t))
|
|
41
38
|
try {
|
|
42
|
-
await
|
|
43
|
-
} catch (
|
|
44
|
-
console.error(
|
|
39
|
+
await r.user.followUser({ userDid: o }), a.success(w("follow_success")), i();
|
|
40
|
+
} catch (s) {
|
|
41
|
+
console.error(s), a.error(d(s));
|
|
45
42
|
}
|
|
46
|
-
}),
|
|
47
|
-
if (!(!
|
|
43
|
+
}), g = f(async (o = t) => {
|
|
44
|
+
if (!(!r || l && o === t))
|
|
48
45
|
try {
|
|
49
|
-
await
|
|
50
|
-
} catch (
|
|
51
|
-
console.error(
|
|
46
|
+
await r.user.unfollowUser({ userDid: o }), a.success(w("unfollow_success")), i();
|
|
47
|
+
} catch (s) {
|
|
48
|
+
console.error(s), a.error(d(s));
|
|
52
49
|
}
|
|
53
50
|
});
|
|
54
|
-
return
|
|
55
|
-
m &&
|
|
56
|
-
}, [
|
|
57
|
-
|
|
58
|
-
}, [
|
|
51
|
+
return F(() => {
|
|
52
|
+
m && t && !l && r && !n && i();
|
|
53
|
+
}, [i, t, l, r, n, m]), F(() => {
|
|
54
|
+
n && c(e?.isFollowing || !1);
|
|
55
|
+
}, [n, e]), {
|
|
59
56
|
followed: p,
|
|
60
|
-
followUser:
|
|
61
|
-
unfollowUser:
|
|
57
|
+
followUser: h,
|
|
58
|
+
unfollowUser: g
|
|
62
59
|
};
|
|
63
60
|
}
|
|
64
61
|
export {
|
|
65
|
-
|
|
66
|
-
F as formatAxiosError
|
|
62
|
+
K as default
|
|
67
63
|
};
|
package/lib/Util/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mergeAllThemeOptions } from '@blocklet/theme';
|
|
2
2
|
import { default as Cookies } from 'js-cookie';
|
|
3
|
+
import { AxiosError } from 'axios';
|
|
3
4
|
import { $TSFixMe, Locale } from '../type';
|
|
4
5
|
declare let dateTool: $TSFixMe | null;
|
|
5
6
|
/** @deprecated for compatibility, please use `import { mergeAllThemeOptions } from '@blocklet/theme'` instead */
|
|
@@ -121,3 +122,4 @@ export declare const compareVersions: (version1: string, version2: string) => bo
|
|
|
121
122
|
* 通过 server 的版本和 ux 的版本共同决定
|
|
122
123
|
*/
|
|
123
124
|
export declare const isSupportFollow: () => boolean;
|
|
125
|
+
export declare const formatAxiosError: (err: AxiosError) => string;
|