import React, { useState } from 'react'; import { Outlet, useNavigate, useSearchParams } from 'react-router-dom'; import { NavItem } from '../components/NavItem'; import { MobileNavItem } from '../components/MobileNavItem'; import { UserOutlined } from '@ant-design/icons'; import { Button, Divider, Drawer, Dropdown } from 'antd'; import { useUserStore } from '../store/user'; import { useLogout } from '../api/model/user'; import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher'; import { version } from '@tianji/shared'; import { useIsMobile } from '../hooks/useIsMobile'; import { RiMenuUnfoldLine } from 'react-icons/ri'; export const Layout: React.FC = React.memo(() => { const [params] = useSearchParams(); const workspaces = useUserStore((state) => { const userInfo = state.info; if (userInfo) { return userInfo.workspaces.map((w) => ({ id: w.workspace.id, name: w.workspace.name, role: w.role, current: userInfo.currentWorkspace?.id === w.workspace.id, })); } return []; }); const [openDraw, setOpenDraw] = useState(false); const logout = useLogout(); const isMobile = useIsMobile(); const showHeader = !params.has('hideHeader'); const navigate = useNavigate(); const accountEl = ( ({ key: w.id, label: `${w.name}${w.current ? '(current)' : ''}`, disabled: w.current, })), }, { key: 'settings', label: 'Settings', onClick: () => { navigate('/settings'); }, }, { key: 'logout', label: 'Logout', onClick: () => { logout(); }, }, { type: 'divider', }, { key: 'version', label: `v${version}`, disabled: true, }, ], }} >