import React, { useReducer } from 'react'; import { Icon } from '@iconify/react'; import { GroupPanelType, useGroupInfo } from 'tailchat-shared'; import { useLocation, useParams } from 'react-router'; import { Badge, Typography } from 'antd'; import { Link } from 'react-router-dom'; import clsx from 'clsx'; interface GroupParams { groupId: string; } const GroupSection: React.FC<{ header: string; }> = React.memo((props) => { const [isShow, switchShow] = useReducer((v) => !v, true); return (
{props.header}
ref?.style.setProperty('--max-height', `${ref.scrollHeight}px`) } > {props.children}
); }); GroupSection.displayName = 'GroupSection'; const GroupPanelItem: React.FC<{ name: string; icon: React.ReactNode; to: string; badge?: boolean; }> = React.memo((props) => { const { icon, name, to, badge } = props; const location = useLocation(); const isActive = location.pathname.startsWith(to); return (
{icon}
{name} {badge === true ? ( ) : ( )}
); }); GroupPanelItem.displayName = 'GroupPanelItem'; /** * 个人面板侧边栏组件 */ export const Sidebar: React.FC = React.memo(() => { const { groupId } = useParams(); const groupInfo = useGroupInfo(groupId); const groupPanels = groupInfo?.panels ?? []; return (
{groupPanels .filter((panel) => panel.type === GroupPanelType.GROUP) .map((group) => ( {groupPanels .filter((panel) => panel.parentId === group.id) .map((panel) => ( #
} to={`/main/group/${groupId}/${panel.id}`} /> ))} ))} ); }); Sidebar.displayName = 'Sidebar';