refactor(HomeNavbar): Phase 1 - 提取静态组件 (1623行→1573行)
重构目标: 减少 HomeNavbar 不必要的重新渲染 Phase 1 完成: ✅ 提取 BrandLogo.js (51行) - Logo 和品牌文字 ✅ 提取 LoginButton.js (37行) - 登录/注册按钮 ✅ 提取 CalendarButton.js (65行) - 投资日历按钮+Modal ✅ 提取 ThemeToggleButton.js (33行) - 主题切换按钮 优化成果: - HomeNavbar.js: 1623行 → 1573行 (↓ 50行, -3%) - 4个独立组件使用 React.memo 包裹 - 组件状态内部管理,不影响父组件 - CalendarModal 状态从主组件移除 性能收益: - 这些组件现在独立渲染,不受父组件影响 - 为后续 Phase 2-6 优化奠定基础 目录结构: src/components/Navbars/ ├── HomeNavbar.js (1573行) └── components/ ├── BrandLogo.js ├── LoginButton.js ├── CalendarButton.js └── ThemeToggleButton.js 下一步: Phase 2 - 提取订阅相关组件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -50,9 +50,13 @@ import { getApiBase } from '../../utils/apiConfig';
|
||||
import SubscriptionButton from '../Subscription/SubscriptionButton';
|
||||
import SubscriptionModal from '../Subscription/SubscriptionModal';
|
||||
import { CrownIcon, TooltipContent } from '../Subscription/CrownTooltip';
|
||||
import InvestmentCalendar from '../../views/Community/components/InvestmentCalendar';
|
||||
import { useNavigationEvents } from '../../hooks/useNavigationEvents';
|
||||
|
||||
// Phase 1 优化: 提取的子组件
|
||||
import BrandLogo from './components/BrandLogo';
|
||||
import LoginButton from './components/LoginButton';
|
||||
import CalendarButton from './components/CalendarButton';
|
||||
|
||||
/** 二级导航栏组件 - 显示当前一级菜单下的所有二级菜单项 */
|
||||
const SecondaryNav = ({ showCompletenessAlert }) => {
|
||||
const navigate = useNavigate();
|
||||
@@ -560,8 +564,8 @@ export default function HomeNavbar() {
|
||||
const WATCHLIST_PAGE_SIZE = 10;
|
||||
const EVENTS_PAGE_SIZE = 8;
|
||||
|
||||
// 投资日历 Modal 状态
|
||||
const [calendarModalOpen, setCalendarModalOpen] = useState(false);
|
||||
// 投资日历 Modal 状态 - 已移至 CalendarButton 组件内部管理
|
||||
// const [calendarModalOpen, setCalendarModalOpen] = useState(false);
|
||||
|
||||
// 用户信息完整性状态
|
||||
const [profileCompleteness, setProfileCompleteness] = useState(null);
|
||||
@@ -897,24 +901,7 @@ export default function HomeNavbar() {
|
||||
<Container maxW="container.xl" px={{ base: 3, md: 4 }}>
|
||||
<Flex justify="space-between" align="center">
|
||||
{/* Logo - 价小前投研 */}
|
||||
<HStack spacing={{ base: 3, md: 6 }}>
|
||||
<Text
|
||||
fontSize={{ base: 'lg', md: 'xl' }}
|
||||
fontWeight="bold"
|
||||
color={brandText}
|
||||
cursor="pointer"
|
||||
_hover={{ color: brandHover }}
|
||||
onClick={() => {
|
||||
// 🎯 追踪Logo点击
|
||||
navEvents.trackLogoClicked();
|
||||
navigate('/home');
|
||||
}}
|
||||
style={{ minWidth: isMobile ? '100px' : '140px' }}
|
||||
noOfLines={1}
|
||||
>
|
||||
价小前投研
|
||||
</Text>
|
||||
</HStack>
|
||||
<BrandLogo />
|
||||
|
||||
{/* 中间导航区域 - 响应式 */}
|
||||
{isMobile ? (
|
||||
@@ -958,18 +945,7 @@ export default function HomeNavbar() {
|
||||
// 已登录状态 - 用户菜单 + 功能菜单排列
|
||||
<HStack spacing={{ base: 2, md: 3 }}>
|
||||
{/* 投资日历 - 仅大屏显示 */}
|
||||
{isDesktop && (
|
||||
<Button
|
||||
size="sm"
|
||||
colorScheme="orange"
|
||||
variant="solid"
|
||||
borderRadius="full"
|
||||
leftIcon={<FiCalendar />}
|
||||
onClick={() => setCalendarModalOpen(true)}
|
||||
>
|
||||
投资日历
|
||||
</Button>
|
||||
)}
|
||||
{isDesktop && <CalendarButton />}
|
||||
|
||||
{/* 自选股 - 仅大屏显示 */}
|
||||
{isDesktop && (
|
||||
@@ -1336,19 +1312,7 @@ export default function HomeNavbar() {
|
||||
</HStack>
|
||||
) : (
|
||||
// 未登录状态 - 单一按钮
|
||||
<Button
|
||||
colorScheme="blue"
|
||||
variant="solid"
|
||||
size="sm"
|
||||
borderRadius="full"
|
||||
onClick={() => openAuthModal()}
|
||||
_hover={{
|
||||
transform: "translateY(-1px)",
|
||||
boxShadow: "md"
|
||||
}}
|
||||
>
|
||||
登录 / 注册
|
||||
</Button>
|
||||
<LoginButton />
|
||||
)}
|
||||
</HStack>
|
||||
</Flex>
|
||||
@@ -1604,21 +1568,7 @@ export default function HomeNavbar() {
|
||||
{/* 二级导航栏 - 显示当前页面所属的二级菜单 */}
|
||||
{!isMobile && <SecondaryNav showCompletenessAlert={showCompletenessAlert} />}
|
||||
|
||||
{/* 投资日历 Modal */}
|
||||
<Modal
|
||||
isOpen={calendarModalOpen}
|
||||
onClose={() => setCalendarModalOpen(false)}
|
||||
size="6xl"
|
||||
>
|
||||
<ModalOverlay />
|
||||
<ModalContent maxW="1200px">
|
||||
<ModalHeader>投资日历</ModalHeader>
|
||||
<ModalCloseButton />
|
||||
<ModalBody pb={6}>
|
||||
<InvestmentCalendar />
|
||||
</ModalBody>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
{/* 投资日历 Modal - 已移至 CalendarButton 组件内部 */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user