import { Link, useLocation } from 'react-router-dom'; import { Avatar } from './Avatar'; import { Icon } from './Icon'; interface NavRailItem { to: string; icon: string; label: string; badge?: number; } const TOP_ITEMS: NavRailItem[] = [ { to: '/messages', icon: 'chat_bubble', label: '消息' }, { to: '/contacts', icon: 'contacts', label: '通讯录' }, { to: '/favorites', icon: 'inventory_2', label: '收藏' }, ]; const BOTTOM_ITEMS: NavRailItem[] = [ { to: '/calls', icon: 'phone', label: '通话记录' }, { to: '/settings', icon: 'settings', label: '设置' }, ]; function isNavItemActive(to: string, pathname: string): boolean { if (to === '/messages') return pathname.startsWith('/messages'); return pathname === to || pathname.startsWith(`${to}/`); } function NavRailButton({ item }: { item: NavRailItem }) { const location = useLocation(); const isActive = isNavItemActive(item.to, location.pathname); return ( // Plain Link, not NavLink -- NavLink computes its OWN `aria-current` from ITS OWN prefix-match // logic unconditionally (confirmed by reading react-router's source: passing an `aria-current` // prop only changes the STRING used, not whether it's applied at all, which stays gated on // NavLink's internal isActive), so a second, independent aria-current computation could in // principle disagree with the `className` highlight computed by `isActive` below. Driving both // off the one shared `isActive` value keeps them impossible to desync. {item.badge ? ( {item.badge} ) : null} ); } interface NavRailProps { unreadMessages?: number; /** The logged-in user's own id/name/avatar (`GET /v1/im/me`) -- drives the rail's top self-tile. * All optional so the rail still renders (as a letter-tile fallback) before that request settles. */ selfId?: string; selfName?: string; selfAvatarFileId?: string; } /** Persistent 64px icon rail, visible at >=640px (see App.tsx for the <640 bottom-tab fallback). */ export function NavRail({ unreadMessages = 0, selfId, selfName, selfAvatarFileId }: NavRailProps) { return ( ); }