import { useEffect, useRef } from 'react';
function rewardDelta(step, prevStep) {
if (!step || !step.reward) return null;
const curr = step.reward.total;
if (prevStep && prevStep.reward) {
return curr - prevStep.reward.total;
}
return curr;
}
export default function StepFeed({ steps, currentStep }) {
const feedRef = useRef(null);
const activeRef = useRef(null);
useEffect(() => {
if (activeRef.current) {
activeRef.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}
}, [currentStep]);
if (!steps || steps.length === 0) {
return (
);
}
return (
{steps.map((step, idx) => {
const stepNum = idx + 1;
const isActive = currentStep === stepNum;
const delta = rewardDelta(step, idx > 0 ? steps[idx - 1] : null);
const asgn = step.fold ? step.fold.assignment : null;
const instruction = step.fold ? step.fold.instruction : (step.prompt || '');
return (
#{stepNum}
{instruction}
{asgn && (
{asgn}
)}
{delta !== null && (
{'\u0394'} total:{' '}
= 0 ? 'delta-positive' : 'delta-negative'}>
{delta >= 0 ? '+' : ''}{delta.toFixed(3)}
{step.reward && (
{' '}| progress: {step.reward.progress.toFixed(2)}
{' '}| economy: {step.reward.economy.toFixed(2)}
)}
)}
);
})}
);
}