import { useState, type ReactNode } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { useTheme } from '../../hooks/useTheme' import Sidebar from './Sidebar' import Header from './Header' import MobileNav from './MobileNav' import TabBar from './TabBar' function useMediaQuery(query: string) { const [matches, setMatches] = useState(() => { if (typeof window !== 'undefined') { return window.matchMedia(query).matches } return false }) if (typeof window !== 'undefined') { const mql = window.matchMedia(query) mql.addEventListener('change', (e) => setMatches(e.matches)) } return matches } export interface AppLayoutProps { children: ReactNode breadcrumb?: string onlineCount?: number runningCount?: number onSearch?: (query: string) => any } export default function AppLayout({ children, breadcrumb, onlineCount = 0, runningCount = 0, onSearch, }: AppLayoutProps) { const { theme, toggle } = useTheme() const navigate = useNavigate() const location = useLocation() const isMobile = useMediaQuery('(max-width: 767px)') const isTablet = useMediaQuery('(min-width: 768px) and (max-width: 1023px)') const [mobileNavOpen, setMobileNavOpen] = useState(false) const handleNavigate = (path: string) => { navigate(path) } const sidebarWidth = isTablet ? 180 : 220 if (isMobile) { return (
{/* Mobile header */}
知微蜂巢
{/* Mobile content */}
{children}
{/* Mobile tab bar */} {/* Mobile nav drawer */} setMobileNavOpen(false)} activePath={location.pathname} onNavigate={handleNavigate} />
) } return (
{/* Sidebar */}
{/* Header */}
{/* Main */}
{children}
) }