@blocklet/ui-react 2.12.64 → 2.12.71
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/index.js +6 -14
- package/lib/Footer/links.js +5 -5
- package/lib/Footer/social-media.js +2 -2
- package/lib/Header/index.js +8 -8
- package/lib/UserCenter/components/editable-field.d.ts +2 -1
- package/lib/UserCenter/components/editable-field.js +3 -2
- package/lib/UserCenter/components/settings.js +11 -1
- package/lib/UserCenter/components/user-info/metadata.js +6 -4
- package/lib/UserSessions/components/user-sessions.d.ts +12 -1
- package/lib/UserSessions/components/user-sessions.js +139 -51
- package/lib/UserSessions/libs/locales.d.ts +2 -0
- package/lib/UserSessions/libs/locales.js +8 -6
- package/lib/common/notification-addon.js +0 -2
- package/package.json +5 -5
- package/src/Footer/index.jsx +8 -13
- package/src/Footer/links.jsx +5 -5
- package/src/Footer/social-media.jsx +2 -2
- package/src/Header/index.tsx +9 -9
- package/src/UserCenter/components/editable-field.tsx +3 -1
- package/src/UserCenter/components/settings.tsx +14 -1
- package/src/UserCenter/components/user-info/metadata.tsx +16 -12
- package/src/UserSessions/components/user-sessions.tsx +130 -43
- package/src/UserSessions/libs/locales.ts +8 -6
- package/src/common/notification-addon.jsx +0 -2
- package/lib/UserCenter/components/user-info/clock.d.ts +0 -3
- package/lib/UserCenter/components/user-info/clock.js +0 -50
- package/lib/hooks/use-clock.d.ts +0 -9
- package/lib/hooks/use-clock.js +0 -49
- package/src/UserCenter/components/user-info/clock.tsx +0 -43
- package/src/hooks/use-clock.tsx +0 -61
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Badge from '@mui/material/Badge';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useCallback, useEffect } from 'react';
|
|
4
|
-
import { temp as colors } from '@arcblock/ux/lib/Colors';
|
|
5
4
|
import { IconButton } from '@mui/material';
|
|
6
5
|
import { useSnackbar } from 'notistack';
|
|
7
6
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
@@ -105,7 +104,6 @@ export default function NotificationAddon({ session = {} }) {
|
|
|
105
104
|
variant="outlined"
|
|
106
105
|
href={viewAllUrl}
|
|
107
106
|
sx={{
|
|
108
|
-
borderColor: colors.lineBorderStrong,
|
|
109
107
|
'&:hover': {
|
|
110
108
|
borderRadius: '50%',
|
|
111
109
|
},
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Tooltip from "@mui/material/Tooltip";
|
|
3
|
-
import Typography from "@mui/material/Typography";
|
|
4
|
-
import Box from "@mui/material/Box";
|
|
5
|
-
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
6
|
-
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
7
|
-
import { useMemoizedFn } from "ahooks";
|
|
8
|
-
import { translations } from "../../libs/locales.js";
|
|
9
|
-
import { useClock } from "../../../hooks/use-clock.js";
|
|
10
|
-
export default function Clock({ value }) {
|
|
11
|
-
const { locale } = useLocaleContext();
|
|
12
|
-
const t = useMemoizedFn((key, data = {}) => {
|
|
13
|
-
return translate(translations, key, locale, "en", data);
|
|
14
|
-
});
|
|
15
|
-
const timeInfo = useClock(value, locale);
|
|
16
|
-
return /* @__PURE__ */ jsxs(
|
|
17
|
-
Box,
|
|
18
|
-
{
|
|
19
|
-
sx: {
|
|
20
|
-
whiteSpace: "nowrap",
|
|
21
|
-
overflow: "hidden",
|
|
22
|
-
textOverflow: "ellipsis"
|
|
23
|
-
},
|
|
24
|
-
display: "flex",
|
|
25
|
-
alignItems: "center",
|
|
26
|
-
gap: 1,
|
|
27
|
-
children: [
|
|
28
|
-
/* @__PURE__ */ jsx(Typography, { children: value }),
|
|
29
|
-
/* @__PURE__ */ jsx(
|
|
30
|
-
Tooltip,
|
|
31
|
-
{
|
|
32
|
-
title: /* @__PURE__ */ jsxs("span", { children: [
|
|
33
|
-
t("profile.localTime"),
|
|
34
|
-
" ",
|
|
35
|
-
timeInfo.fullDateTime
|
|
36
|
-
] }),
|
|
37
|
-
placement: "top",
|
|
38
|
-
arrow: true,
|
|
39
|
-
children: /* @__PURE__ */ jsxs(Typography, { component: "span", fontSize: 14, children: [
|
|
40
|
-
"(",
|
|
41
|
-
locale === "zh" ? `${t(`profile.timezonePhase.${timeInfo.phase}`)} ` : "",
|
|
42
|
-
timeInfo.formattedTime,
|
|
43
|
-
")"
|
|
44
|
-
] })
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
}
|
package/lib/hooks/use-clock.d.ts
DELETED
package/lib/hooks/use-clock.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from "react";
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
import utc from "dayjs/plugin/utc";
|
|
4
|
-
import timezonePlugin from "dayjs/plugin/timezone";
|
|
5
|
-
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
6
|
-
import { formatToDatetime } from "@arcblock/ux/lib/Util";
|
|
7
|
-
import "dayjs/locale/zh-cn";
|
|
8
|
-
import "dayjs/locale/en";
|
|
9
|
-
dayjs.extend(utc);
|
|
10
|
-
dayjs.extend(timezonePlugin);
|
|
11
|
-
dayjs.extend(localizedFormat);
|
|
12
|
-
const currentTimezone = dayjs.tz.guess();
|
|
13
|
-
const getTimePhase = (hour) => {
|
|
14
|
-
if (hour >= 0 && hour < 6)
|
|
15
|
-
return { phase: "dawn", icon: "\u{1F312}" };
|
|
16
|
-
if (hour >= 6 && hour < 12)
|
|
17
|
-
return { phase: "morning", icon: "\u{1F31E}" };
|
|
18
|
-
if (hour >= 12 && hour < 18)
|
|
19
|
-
return { phase: "afternoon", icon: "\u{1F31E}" };
|
|
20
|
-
return { phase: "night", icon: "\u{1F312}" };
|
|
21
|
-
};
|
|
22
|
-
export function useClock(timezone = currentTimezone, locale = "zh") {
|
|
23
|
-
const getLatestTimeInfo = useCallback(() => {
|
|
24
|
-
const currentLocale = locale === "zh" ? "zh-cn" : "en";
|
|
25
|
-
const localeOption = locale === "zh" ? "zh-cn" : "en-us";
|
|
26
|
-
dayjs.locale(currentLocale);
|
|
27
|
-
const now = dayjs().tz(timezone);
|
|
28
|
-
const hour = now.hour();
|
|
29
|
-
const { phase, icon } = getTimePhase(hour);
|
|
30
|
-
return {
|
|
31
|
-
formattedTime: now.format("LT"),
|
|
32
|
-
fullDateTime: formatToDatetime(now.toDate(), { tz: timezone, locale: localeOption }),
|
|
33
|
-
phase,
|
|
34
|
-
icon,
|
|
35
|
-
rawTime: now
|
|
36
|
-
};
|
|
37
|
-
}, [timezone, locale]);
|
|
38
|
-
const [timeInfo, setTimeInfo] = useState(getLatestTimeInfo());
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
setTimeInfo(getLatestTimeInfo());
|
|
41
|
-
const timerId = setInterval(() => {
|
|
42
|
-
setTimeInfo(getLatestTimeInfo());
|
|
43
|
-
}, 6e3);
|
|
44
|
-
return () => {
|
|
45
|
-
clearInterval(timerId);
|
|
46
|
-
};
|
|
47
|
-
}, [timezone, locale, getLatestTimeInfo]);
|
|
48
|
-
return timeInfo;
|
|
49
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Tooltip from '@mui/material/Tooltip';
|
|
2
|
-
import Typography from '@mui/material/Typography';
|
|
3
|
-
import Box from '@mui/material/Box';
|
|
4
|
-
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
5
|
-
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
|
-
import { useMemoizedFn } from 'ahooks';
|
|
7
|
-
import { translations } from '../../libs/locales';
|
|
8
|
-
import { useClock } from '../../../hooks/use-clock';
|
|
9
|
-
|
|
10
|
-
export default function Clock({ value }: { value: string }) {
|
|
11
|
-
const { locale } = useLocaleContext();
|
|
12
|
-
const t = useMemoizedFn((key, data = {}) => {
|
|
13
|
-
return translate(translations, key, locale, 'en', data);
|
|
14
|
-
});
|
|
15
|
-
const timeInfo = useClock(value, locale);
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<Box
|
|
19
|
-
sx={{
|
|
20
|
-
whiteSpace: 'nowrap',
|
|
21
|
-
overflow: 'hidden',
|
|
22
|
-
textOverflow: 'ellipsis',
|
|
23
|
-
}}
|
|
24
|
-
display="flex"
|
|
25
|
-
alignItems="center"
|
|
26
|
-
gap={1}>
|
|
27
|
-
<Typography>{value}</Typography>
|
|
28
|
-
<Tooltip
|
|
29
|
-
title={
|
|
30
|
-
<span>
|
|
31
|
-
{t('profile.localTime')} {timeInfo.fullDateTime}
|
|
32
|
-
</span>
|
|
33
|
-
}
|
|
34
|
-
placement="top"
|
|
35
|
-
arrow>
|
|
36
|
-
<Typography component="span" fontSize={14}>
|
|
37
|
-
({locale === 'zh' ? `${t(`profile.timezonePhase.${timeInfo.phase}`)} ` : ''}
|
|
38
|
-
{timeInfo.formattedTime})
|
|
39
|
-
</Typography>
|
|
40
|
-
</Tooltip>
|
|
41
|
-
</Box>
|
|
42
|
-
);
|
|
43
|
-
}
|
package/src/hooks/use-clock.tsx
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import utc from 'dayjs/plugin/utc';
|
|
4
|
-
import timezonePlugin from 'dayjs/plugin/timezone';
|
|
5
|
-
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
6
|
-
import { formatToDatetime } from '@arcblock/ux/lib/Util';
|
|
7
|
-
import 'dayjs/locale/zh-cn';
|
|
8
|
-
import 'dayjs/locale/en';
|
|
9
|
-
|
|
10
|
-
dayjs.extend(utc);
|
|
11
|
-
dayjs.extend(timezonePlugin);
|
|
12
|
-
dayjs.extend(localizedFormat);
|
|
13
|
-
|
|
14
|
-
const currentTimezone = dayjs.tz.guess();
|
|
15
|
-
|
|
16
|
-
// 获取时间段
|
|
17
|
-
const getTimePhase = (hour: number) => {
|
|
18
|
-
if (hour >= 0 && hour < 6) return { phase: 'dawn', icon: '🌒' }; // 凌晨 00:00-05:59
|
|
19
|
-
if (hour >= 6 && hour < 12) return { phase: 'morning', icon: '🌞' }; // 上午 06:00-11:59
|
|
20
|
-
if (hour >= 12 && hour < 18) return { phase: 'afternoon', icon: '🌞' }; // 下午 12:00-17:59
|
|
21
|
-
return { phase: 'night', icon: '🌒' }; // 晚上 18:00-23:59
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function useClock(timezone = currentTimezone, locale = 'zh') {
|
|
25
|
-
const getLatestTimeInfo = useCallback(() => {
|
|
26
|
-
const currentLocale = locale === 'zh' ? 'zh-cn' : 'en';
|
|
27
|
-
const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
|
|
28
|
-
dayjs.locale(currentLocale);
|
|
29
|
-
|
|
30
|
-
const now = dayjs().tz(timezone);
|
|
31
|
-
const hour = now.hour();
|
|
32
|
-
const { phase, icon } = getTimePhase(hour);
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
formattedTime: now.format('LT'),
|
|
36
|
-
fullDateTime: formatToDatetime(now.toDate(), { tz: timezone, locale: localeOption }),
|
|
37
|
-
phase,
|
|
38
|
-
icon,
|
|
39
|
-
rawTime: now,
|
|
40
|
-
};
|
|
41
|
-
}, [timezone, locale]);
|
|
42
|
-
|
|
43
|
-
const [timeInfo, setTimeInfo] = useState(getLatestTimeInfo());
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
// 立即更新一次,确保初始状态是最新的
|
|
47
|
-
setTimeInfo(getLatestTimeInfo());
|
|
48
|
-
|
|
49
|
-
// 设置定时器
|
|
50
|
-
const timerId = setInterval(() => {
|
|
51
|
-
setTimeInfo(getLatestTimeInfo());
|
|
52
|
-
}, 6000);
|
|
53
|
-
|
|
54
|
-
// 清理函数
|
|
55
|
-
return () => {
|
|
56
|
-
clearInterval(timerId);
|
|
57
|
-
};
|
|
58
|
-
}, [timezone, locale, getLatestTimeInfo]);
|
|
59
|
-
|
|
60
|
-
return timeInfo;
|
|
61
|
-
}
|