import { ExternalLink, LayoutDashboard, ArrowUpRight } from 'lucide-react'; import { useMemo, useState } from 'react'; import { Button } from '@/components/ui/button'; import { ChevronDown, ChevronUp } from 'lucide-react'; import { useNavigate } from '@tanstack/react-router'; interface InfoItem { title: string; value: string; description: string; } interface DashCardProps { isCNB: boolean; liveData: { list?: InfoItem[] } | null; } const DEFAULT_SHOW_COUNT = 12; function isUrl(value: string): boolean { try { const url = new URL(value); return url.protocol === 'http:' || url.protocol === 'https:'; } catch { return false; } } export function DashCard({ isCNB, liveData }: DashCardProps) { const [expanded, setExpanded] = useState(false); if (!isCNB || !liveData?.list?.length) return null; const data = useMemo(() => { if (!liveData?.list) return { docs: null, list: [] }; const docs = liveData.list.find((item) => item.title === 'docs'); const list = liveData.list.filter((item) => item.title !== 'docs'); return { docs, list } }, [liveData]); const showList = expanded ? data.list : data.list.slice(0, DEFAULT_SHOW_COUNT); const hasMore = data.list.length > DEFAULT_SHOW_COUNT; return (
{showList.map((item) => (
{item.title}
{item.value ? ( isUrl(item.value) ? ( {item.value} ) : (
{item.value}
) ) : (
(空)
)} {item.description && (
{item.description}
)}
))}
{hasMore && (
)}
); } export const DashTitle = () => { const navigate = useNavigate(); const toCNBBoard = () => { navigate({ to: '/cnb-board' }); } return (
CNB Board 实时信息
); }