130 lines
4.2 KiB
React
130 lines
4.2 KiB
React
import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js';
|
||
import React, { useMemo } from 'react';
|
||
import { useLocation } from 'react-router-dom';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { BrainCircuit, Image, Video } from 'lucide-react';
|
||
import { useSidebarCollapsed } from '../../../hooks/common/useSidebarCollapsed';
|
||
import { useSidebarNavigation } from '../../../hooks/common/useTopNavigation';
|
||
import { useExperienceModules } from '../useExperienceModules';
|
||
import { badgeText } from '../../../hooks/creation/creationWatch';
|
||
|
||
import {
|
||
CenterSidebar,
|
||
CenterSidebarItem,
|
||
} from '../../../components/layout/components/CenterSidebar';
|
||
|
||
/**
|
||
* 体验中心桌面侧栏:结构、样式与收起交互对齐用户中心侧栏(UserCenterSidebar),
|
||
* 共用 center-layout.css 的 .ui-center-sidebar / .ui-center-menu-item / .ui-center-sidebar-collapse,
|
||
* 收起状态与其他中心侧栏共用 useSidebarCollapsed。
|
||
*
|
||
* @param {{ unread?: { image: number, video: number } }} props
|
||
* unread:新创作台中用户不在该页时完成的作品数(WP C-4 未读角标)
|
||
*/
|
||
const ExperienceSidebar = ({ unread }) => {
|
||
const { t } = useTranslation();
|
||
const [collapsed, toggleCollapsed] = useSidebarCollapsed();
|
||
const followSidebarLink = useSidebarNavigation();
|
||
const location = useLocation();
|
||
const { isAvailable } = useExperienceModules();
|
||
|
||
const allNavItems = useMemo(
|
||
() => [
|
||
{
|
||
text: t('云端大脑'),
|
||
itemKey: 'cloud-brain',
|
||
configKey: 'cloudBrain',
|
||
to: '/experience-center/cloud-brain',
|
||
icon: BrainCircuit,
|
||
beta: true,
|
||
},
|
||
{
|
||
text: t('图片生成'),
|
||
itemKey: 'image-generation',
|
||
configKey: 'imageGeneration',
|
||
to: '/experience-center/image-generation',
|
||
icon: Image,
|
||
unreadKey: 'image',
|
||
},
|
||
{
|
||
text: t('视频生成'),
|
||
itemKey: 'video-generation',
|
||
configKey: 'videoGeneration',
|
||
to: '/experience-center/video-generation',
|
||
icon: Video,
|
||
unreadKey: 'video',
|
||
},
|
||
],
|
||
[t],
|
||
);
|
||
|
||
// 根据配置过滤导航项(与默认落地页共用 useExperienceModules 判定)
|
||
const navItems = useMemo(
|
||
() => allNavItems.filter((item) => isAvailable(item.configKey)),
|
||
[allNavItems, isAvailable],
|
||
);
|
||
|
||
// 选中项直接由当前路径推导,避免额外状态与路由不同步
|
||
const selectedKey =
|
||
navItems.find((item) => location.pathname.startsWith(item.to))?.itemKey ||
|
||
'';
|
||
|
||
return (
|
||
<CenterSidebar
|
||
className='ui-experience-sidebar'
|
||
collapsed={collapsed}
|
||
onToggle={toggleCollapsed}
|
||
>
|
||
<div className='ui-org-group-items'>
|
||
{navItems.map((item) => {
|
||
const active = selectedKey === item.itemKey;
|
||
const Icon = item.icon;
|
||
const unreadCount =
|
||
item.unreadKey && !active ? unread?.[item.unreadKey] || 0 : 0;
|
||
const unreadLabel = unreadCount
|
||
? t('{{n}} 个新作品', { n: unreadCount })
|
||
: '';
|
||
|
||
return (
|
||
<CenterSidebarItem
|
||
key={item.itemKey}
|
||
to={item.to}
|
||
label={item.text}
|
||
collapsed={collapsed}
|
||
active={active}
|
||
icon={<Icon size={16} strokeWidth={1.5} aria-hidden='true' />}
|
||
onClick={(event) => followSidebarLink(item.to, event)}
|
||
aria-label={
|
||
unreadLabel
|
||
? `${item.text}(${unreadLabel})`
|
||
: collapsed
|
||
? item.text
|
||
: undefined
|
||
}
|
||
trailing={
|
||
<>
|
||
{!collapsed && item.beta && (
|
||
<span className='ui-org-beta'>
|
||
{I18N_TECHNICAL_TEXT.BETA}
|
||
</span>
|
||
)}
|
||
{unreadCount > 0 && (
|
||
<span
|
||
className='exp-unread-badge ui-experience-unread'
|
||
aria-hidden='true'
|
||
>
|
||
{badgeText(unreadCount)}
|
||
</span>
|
||
)}
|
||
</>
|
||
}
|
||
/>
|
||
);
|
||
})}
|
||
</div>
|
||
</CenterSidebar>
|
||
);
|
||
};
|
||
|
||
export default ExperienceSidebar;
|