// TaskBadge — the app-wide floating indicator for in-flight debug tasks. Sits // bottom-right on every page so a streaming upload/download stays visible after // you switch tabs. Collapsed: a chip with a ring-progress + count. Expanded: a // list with per-task progress, cancel (running) / dismiss (finished). Renders // nothing when there are no tasks at all. import { useState } from 'react'; import { AnimatePresence, motion } from 'motion/react'; import { CheckCircle2, Loader2, X, XCircle } from 'lucide-react'; import { useDebugTasks, useRunningTaskSummary, type DebugTask } from '@/contexts/DebugTaskContext'; import { cn } from '@/lib/utils'; function StatusIcon({ status }: { status: DebugTask['status'] }) { if (status === 'running') return ; if (status === 'done') return ; return ; } function Row({ task, onDismiss }: { task: DebugTask; onDismiss: () => void }) { const pct = typeof task.progress === 'number' ? Math.round(task.progress * 100) : null; return (
{task.label} {task.status === 'running' && task.cancel ? : }
{task.status === 'running' && (
)} {task.detail && task.status !== 'running' && ( {task.detail} )}
); } export function TaskBadge() { const { tasks, remove, clearFinished } = useDebugTasks(); const { count, progress } = useRunningTaskSummary(); const [open, setOpen] = useState(false); if (tasks.length === 0) return null; const ringPct = progress === null ? null : Math.round(progress * 100); return (
{open && (
调试任务 {tasks.some((t) => t.status !== 'running') && ( )}
{tasks.map((t) => remove(t.id)} />)}
)}
); }