@blocklet/ui-react 3.1.27 → 3.1.30
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/Footer/links.js +26 -33
- package/lib/UserCenter/components/fallback.d.ts +2 -1
- package/lib/UserCenter/components/fallback.js +17 -16
- package/lib/UserCenter/components/user-center.js +187 -173
- package/lib/UserCenter/components/user-info/social-actions/chat.js +12 -11
- package/lib/UserCenter/components/user-info/user-basic-info.d.ts +2 -1
- package/lib/UserCenter/components/user-info/user-basic-info.js +45 -44
- package/lib/blocklets.js +56 -54
- package/lib/common/notification-addon.js +8 -8
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +36 -43
- package/package.json +9 -10
- package/src/Footer/links.jsx +10 -7
- package/src/UserCenter/components/fallback.tsx +6 -0
- package/src/UserCenter/components/user-center.tsx +16 -6
- package/src/UserCenter/components/user-info/social-actions/chat.tsx +2 -1
- package/src/UserCenter/components/user-info/user-basic-info.tsx +3 -1
- package/src/blocklets.js +5 -1
- package/src/common/notification-addon.jsx +1 -1
- package/src/utils.js +5 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children, cloneElement, isValidElement, use } from 'react';
|
|
1
|
+
import { Children, cloneElement, isValidElement, use, useMemo } from 'react';
|
|
2
2
|
import { Box, CircularProgress, Divider, Typography } from '@mui/material';
|
|
3
3
|
import type { BoxProps, Theme } from '@mui/material';
|
|
4
4
|
import { useCreation, useMemoizedFn, useRequest } from 'ahooks';
|
|
@@ -19,6 +19,7 @@ import cloneDeep from 'lodash/cloneDeep';
|
|
|
19
19
|
import { getQuery, withQuery, joinURL, withoutTrailingSlash } from 'ufo';
|
|
20
20
|
import type { AxiosError } from 'axios';
|
|
21
21
|
import type { UserPublicInfo } from '@blocklet/js-sdk';
|
|
22
|
+
import { isSupportFollow } from '@arcblock/ux/lib/Util';
|
|
22
23
|
|
|
23
24
|
import { PROFILE_URL } from '@arcblock/ux/lib/Util/constant';
|
|
24
25
|
import Footer from '../../Footer';
|
|
@@ -143,6 +144,10 @@ export default function UserCenter({
|
|
|
143
144
|
return false;
|
|
144
145
|
}, [currentDid, session?.user?.did]);
|
|
145
146
|
|
|
147
|
+
const isShowSocialActions = useMemo((): boolean => {
|
|
148
|
+
return isSupportFollow();
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
146
151
|
const userState = useRequest<UserPublicInfo | User | undefined, []>(
|
|
147
152
|
// eslint-disable-next-line consistent-return
|
|
148
153
|
async () => {
|
|
@@ -227,9 +232,9 @@ export default function UserCenter({
|
|
|
227
232
|
value: userFollowersLink,
|
|
228
233
|
url: getLink(userFollowersLink, locale),
|
|
229
234
|
};
|
|
230
|
-
let tabs: NavigationTabProps[] = [nftTab, userFollowersTab];
|
|
235
|
+
let tabs: NavigationTabProps[] = isShowSocialActions ? [nftTab, userFollowersTab] : [nftTab];
|
|
231
236
|
if (isMyself) {
|
|
232
|
-
|
|
237
|
+
const restTabs = [
|
|
233
238
|
nftTab,
|
|
234
239
|
{
|
|
235
240
|
label: t('common.setting'),
|
|
@@ -245,11 +250,11 @@ export default function UserCenter({
|
|
|
245
250
|
value: didSpacesLink,
|
|
246
251
|
url: getLink(didSpacesLink, locale),
|
|
247
252
|
},
|
|
248
|
-
userFollowersTab,
|
|
249
253
|
];
|
|
254
|
+
tabs = isShowSocialActions ? [...restTabs, userFollowersTab] : restTabs;
|
|
250
255
|
}
|
|
251
256
|
return tabs;
|
|
252
|
-
}, [isMyself, locale]);
|
|
257
|
+
}, [isMyself, locale, isShowSocialActions]);
|
|
253
258
|
|
|
254
259
|
const userCenterTabs = useCreation<UserCenterTab[]>(() => {
|
|
255
260
|
const menus = formattedBlocklet?.navigation?.userCenter || [];
|
|
@@ -442,7 +447,10 @@ export default function UserCenter({
|
|
|
442
447
|
|
|
443
448
|
return (
|
|
444
449
|
<Box sx={{ flex: 1 }}>
|
|
445
|
-
<Fallback
|
|
450
|
+
<Fallback
|
|
451
|
+
isSupportFollow={isShowSocialActions}
|
|
452
|
+
currentActiveTab={currentActiveTab as UserCenterTab}
|
|
453
|
+
isMyself={isMyself}>
|
|
446
454
|
{children ? <Box {...contentProps}>{renderChildrenWithProps(children)}</Box> : renderDefaultTab}
|
|
447
455
|
</Fallback>
|
|
448
456
|
</Box>
|
|
@@ -534,6 +542,7 @@ export default function UserCenter({
|
|
|
534
542
|
showFullDid={false}
|
|
535
543
|
onlyProfile={onlyProfile}
|
|
536
544
|
refreshProfile={onRefreshUser}
|
|
545
|
+
isShowSocialActions={isShowSocialActions}
|
|
537
546
|
sx={{
|
|
538
547
|
padding: !isMobile ? '40px 24px 24px 40px' : '16px 0 0 0',
|
|
539
548
|
...(!isMobile ? { width: 320, maxWidth: 320, flexShrink: 0 } : {}),
|
|
@@ -617,6 +626,7 @@ export default function UserCenter({
|
|
|
617
626
|
user={userState.data as User}
|
|
618
627
|
refreshProfile={onRefreshUser}
|
|
619
628
|
showFullDid={false}
|
|
629
|
+
isShowSocialActions={isShowSocialActions}
|
|
620
630
|
sx={{
|
|
621
631
|
padding: !isMobile ? '40px 24px 24px 40px' : '16px 0 0 0',
|
|
622
632
|
...(!isMobile ? { width: 320, maxWidth: 320, flexShrink: 0 } : {}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { Button } from '@mui/material';
|
|
3
3
|
import { useMemoizedFn } from 'ahooks';
|
|
4
|
+
import { Icon } from '@iconify/react';
|
|
4
5
|
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
5
6
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
7
|
|
|
@@ -33,7 +34,7 @@ function Chat({ user }: { user: User }) {
|
|
|
33
34
|
|
|
34
35
|
return (
|
|
35
36
|
<Button fullWidth variant="outlined" color="inherit" onClick={onNavigateToChat}>
|
|
36
|
-
<
|
|
37
|
+
<Icon icon="tabler:message-dots" style={{ marginRight: 4 }} />
|
|
37
38
|
{t('profile.chat')}
|
|
38
39
|
</Button>
|
|
39
40
|
);
|
|
@@ -35,6 +35,7 @@ export default function UserBasicInfo({
|
|
|
35
35
|
isMobile = false,
|
|
36
36
|
onlyProfile = false,
|
|
37
37
|
refreshProfile,
|
|
38
|
+
isShowSocialActions = false,
|
|
38
39
|
...rest
|
|
39
40
|
}: {
|
|
40
41
|
user: User;
|
|
@@ -46,6 +47,7 @@ export default function UserBasicInfo({
|
|
|
46
47
|
isMobile?: boolean;
|
|
47
48
|
onlyProfile?: boolean;
|
|
48
49
|
refreshProfile: () => void;
|
|
50
|
+
isShowSocialActions?: boolean;
|
|
49
51
|
} & BoxProps) {
|
|
50
52
|
const { locale } = useLocaleContext();
|
|
51
53
|
const [userStatus, setUserStatus] = useState<UserMetadata['status']>(undefined);
|
|
@@ -226,7 +228,7 @@ export default function UserBasicInfo({
|
|
|
226
228
|
<DID did={user.did} showQrcode copyable compact={!showFullDid} responsive={!showFullDid} locale={locale} />
|
|
227
229
|
</Box>
|
|
228
230
|
</Box>
|
|
229
|
-
{!isMyself ? (
|
|
231
|
+
{!isMyself && isShowSocialActions ? (
|
|
230
232
|
<Box sx={{ mt: 2 }}>
|
|
231
233
|
<SocialActions user={user} />
|
|
232
234
|
</Box>
|
package/src/blocklets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mapRecursive, filterRecursive, isUrl } from './utils';
|
|
1
|
+
import { mapRecursive, filterRecursive, isUrl, isMailProtocol } from './utils';
|
|
2
2
|
|
|
3
3
|
export const publicPath = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || '/';
|
|
4
4
|
|
|
@@ -28,6 +28,10 @@ export const getLink = (link, locale = 'en') => {
|
|
|
28
28
|
url.searchParams.set('locale', locale);
|
|
29
29
|
return url.href;
|
|
30
30
|
}
|
|
31
|
+
// 如果是 mailto 协议, 直接返回
|
|
32
|
+
if (isMailProtocol(link)) {
|
|
33
|
+
return link;
|
|
34
|
+
}
|
|
31
35
|
const url = new URL(link, window.location.origin);
|
|
32
36
|
url.searchParams.set('locale', locale);
|
|
33
37
|
return url.pathname + url.search;
|
|
@@ -6,10 +6,10 @@ import NotificationsOutlinedIcon from '@arcblock/icons/lib/Notification';
|
|
|
6
6
|
import { useCreation } from 'ahooks';
|
|
7
7
|
import { EVENTS, WELLKNOWN_SERVICE_PATH_PREFIX } from '@abtnode/constant';
|
|
8
8
|
import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
|
|
9
|
+
import { compareVersions } from '@arcblock/ux/lib/Util';
|
|
9
10
|
import { joinURL, withQuery } from 'ufo';
|
|
10
11
|
import { useListenWsClient } from './ws';
|
|
11
12
|
import NotificationSnackbar from '../Notifications/Snackbar';
|
|
12
|
-
import { compareVersions } from '../utils';
|
|
13
13
|
|
|
14
14
|
const viewAllUrl = joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, 'user', 'notifications');
|
|
15
15
|
|
package/src/utils.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import semver from 'semver';
|
|
2
|
-
|
|
3
1
|
export const mapRecursive = (array, fn, childrenKey = 'children') => {
|
|
4
2
|
return array.map((item) => {
|
|
5
3
|
if (Array.isArray(item[childrenKey])) {
|
|
@@ -47,6 +45,11 @@ export const isUrl = (str) => {
|
|
|
47
45
|
return /^https?:\/\//.test(str);
|
|
48
46
|
};
|
|
49
47
|
|
|
48
|
+
// 链接是否是 mailto 协议
|
|
49
|
+
export const isMailProtocol = (str) => {
|
|
50
|
+
return /^mailto:/i.test(str.trim());
|
|
51
|
+
};
|
|
52
|
+
|
|
50
53
|
/**
|
|
51
54
|
* @description 检测是否是 Iconify 格式的字符串
|
|
52
55
|
* @deprecated
|
|
@@ -153,27 +156,3 @@ export const splitNavColumns = (items, options = {}) => {
|
|
|
153
156
|
|
|
154
157
|
return result;
|
|
155
158
|
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 比较两个版本号,用于判断版本号是否兼容
|
|
159
|
-
* @param {*} version1
|
|
160
|
-
* @param {*} version2
|
|
161
|
-
* @returns 0: 版本相同, -1: version1 < version2, 1: version1 > version2
|
|
162
|
-
*/
|
|
163
|
-
export const compareVersions = (version1, version2) => {
|
|
164
|
-
const getDateVersion = (version) => {
|
|
165
|
-
const match = version.match(/^(\d+\.\d+\.\d+(?:-[^-]+?-\d{8}))/);
|
|
166
|
-
return match ? match[1] : version;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const dateVersion1 = getDateVersion(version1);
|
|
170
|
-
const dateVersion2 = getDateVersion(version2);
|
|
171
|
-
|
|
172
|
-
// 如果基础版本相同,但完整版本不同(意味着有额外部分),返回false
|
|
173
|
-
if (dateVersion1 === dateVersion2 && version1 !== version2) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// 其他情况正常比较
|
|
178
|
-
return semver.gte(dateVersion1, dateVersion2);
|
|
179
|
-
};
|