diff --git a/src/frontend/src/components/CheckpointPanel.tsx b/src/frontend/src/components/CheckpointPanel.tsx index 141278c..879899a 100644 --- a/src/frontend/src/components/CheckpointPanel.tsx +++ b/src/frontend/src/components/CheckpointPanel.tsx @@ -288,24 +288,35 @@ export default function CheckpointPanel({ onDone: () => void; }) { const [checkpoints, setCheckpoints] = useState([]); - const [activeIdx, setActiveIdx] = useState(0); + const [pendingIdx, setPendingIdx] = useState(0); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); useEffect(() => { const pid = getProjectId(); - if (!pid) return; + if (!pid) { setLoading(false); return; } + setLoading(true); + setError(null); fetch(`/api/projects/${pid}/tasks/${taskId}/checkpoints`) .then(r => r.json()) - .then(d => setCheckpoints(d.checkpoints || [])) - .catch(() => {}); + .then(d => { setCheckpoints(d.checkpoints || []); setLoading(false); }) + .catch(() => { setError('加载失败'); setLoading(false); }); }, [taskId]); - const cp = checkpoints[activeIdx]; - if (!cp) return null; + if (loading) return
加载中...
; + if (error) return ( +
+
{error}
+ +
+ ); - // 只显示 pending 的 + // 只显示 pending 的(BUG-34: 直接基于 pendingCps 管理索引) const pendingCps = checkpoints.filter(c => c.status === 'pending'); - const activeCp = pendingCps[activeIdx] || pendingCps[0]; - if (!activeCp) return
所有 Checkpoint 已处理
; + if (pendingCps.length === 0) return
所有 Checkpoint 已处理
; + + const activeCp = pendingCps[pendingIdx] || pendingCps[0]; + const activeIdx = pendingCps.indexOf(activeCp); const typeIcon = activeCp.type === 'verify' ? '🔍' : activeCp.type === 'decision' ? '🎯' : '🔧'; const typeColor = activeCp.type === 'verify' ? '#6a9eff' : activeCp.type === 'decision' ? '#818cf8' : '#f59e0b'; @@ -318,7 +329,7 @@ export default function CheckpointPanel({
{pendingCps.map((c, i) => (