/**
* GlobalSidebar - 全局右侧工具栏
*
* 可收起/展开的侧边栏,包含关注股票和事件动态
*/
import React from 'react';
import {
Box,
VStack,
Icon,
IconButton,
Tooltip,
Badge,
Spinner,
Center,
} from '@chakra-ui/react';
import { ChevronLeft, ChevronRight, BarChart2, Star } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import { useGlobalSidebar } from '@/contexts/GlobalSidebarContext';
import { useAuth } from '@/contexts/AuthContext';
import { getEventDetailUrl } from '@/utils/idEncoder';
import WatchSidebar from '@views/Profile/components/WatchSidebar';
/**
* 收起状态下的图标菜单
*/
const CollapsedMenu = ({ watchlist, followingEvents, onToggle }) => {
return (
{/* 展开按钮 */}
}
size="sm"
variant="ghost"
color="rgba(255, 255, 255, 0.6)"
_hover={{ color: 'rgba(212, 175, 55, 0.9)', bg: 'rgba(255, 255, 255, 0.05)' }}
onClick={onToggle}
aria-label="展开工具栏"
/>
{/* 关注股票图标 */}
{watchlist.length > 0 && (
{watchlist.length > 99 ? '99+' : watchlist.length}
)}
{/* 事件动态图标 */}
{followingEvents.length > 0 && (
{followingEvents.length > 99 ? '99+' : followingEvents.length}
)}
);
};
/**
* GlobalSidebar 主组件
*/
const GlobalSidebar = () => {
const { user } = useAuth();
const navigate = useNavigate();
const {
isOpen,
toggle,
watchlist,
realtimeQuotes,
followingEvents,
eventComments,
loading,
unwatchStock,
unfollowEvent,
} = useGlobalSidebar();
// 未登录时不显示
if (!user) {
return null;
}
return (
{/* 加载状态 */}
{loading && (
)}
{isOpen ? (
/* 展开状态 */
{/* 收起按钮 */}
}
size="xs"
variant="ghost"
color="rgba(255, 255, 255, 0.4)"
_hover={{ color: 'rgba(212, 175, 55, 0.9)', bg: 'rgba(255, 255, 255, 0.05)' }}
onClick={toggle}
aria-label="收起工具栏"
/>
{/* WatchSidebar 内容 */}
navigate(`/company/${stock.stock_code}`)}
onEventClick={(event) => navigate(getEventDetailUrl(event.id))}
onCommentClick={(comment) => navigate(getEventDetailUrl(comment.event_id))}
onAddStock={() => navigate('/stocks')}
onAddEvent={() => navigate('/community')}
onUnwatch={unwatchStock}
onUnfollow={unfollowEvent}
/>
) : (
/* 收起状态 */
)}
);
};
export default GlobalSidebar;