fix: 修复顶部导航和侧边栏菜单连点bug,封装公共侧边栏菜单组件并统一ui样式与交互
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js';
|
||||
import {
|
||||
ChevronRight as ActionChevronRight,
|
||||
ChevronLeft as ActionChevronLeft,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
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,
|
||||
@@ -22,6 +24,7 @@ import { badgeText } from '../../../hooks/creation/creationWatch';
|
||||
const ExperienceSidebar = ({ unread }) => {
|
||||
const { t } = useTranslation();
|
||||
const [collapsed, toggleCollapsed] = useSidebarCollapsed();
|
||||
const followSidebarLink = useSidebarNavigation();
|
||||
const location = useLocation();
|
||||
const { isAvailable } = useExperienceModules();
|
||||
|
||||
@@ -67,69 +70,59 @@ const ExperienceSidebar = ({ unread }) => {
|
||||
'';
|
||||
|
||||
return (
|
||||
<aside
|
||||
className='ui-experience-sidebar ui-center-sidebar'
|
||||
data-collapsed={collapsed}
|
||||
<CenterSidebar
|
||||
className='ui-experience-sidebar'
|
||||
collapsed={collapsed}
|
||||
onToggle={toggleCollapsed}
|
||||
>
|
||||
<nav className='ui-center-sidebar-nav'>
|
||||
<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 })
|
||||
: '';
|
||||
<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 (
|
||||
<Link
|
||||
key={item.itemKey}
|
||||
to={item.to}
|
||||
className='ui-center-menu-item'
|
||||
data-active={active || undefined}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
aria-label={
|
||||
unreadLabel ? `${item.text}(${unreadLabel})` : undefined
|
||||
}
|
||||
title={collapsed ? item.text : undefined}
|
||||
>
|
||||
<Icon size={16} strokeWidth={1.5} aria-hidden='true' />
|
||||
{!collapsed && (
|
||||
<span className='ui-center-menu-label'>{item.text}</span>
|
||||
)}
|
||||
{!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>
|
||||
) : null}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</nav>
|
||||
<button
|
||||
type='button'
|
||||
className='app-action-button ui-center-sidebar-collapse'
|
||||
onClick={toggleCollapsed}
|
||||
aria-label={collapsed ? t('展开导航') : t('收起导航')}
|
||||
>
|
||||
{collapsed ? (
|
||||
<ActionChevronRight size={16} />
|
||||
) : (
|
||||
<ActionChevronLeft size={16} />
|
||||
)}
|
||||
{!collapsed && <span>{t('收起导航')}</span>}
|
||||
</button>
|
||||
</aside>
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user