mirror of
https://github.com/csunny/DB-GPT.git
synced 2026-07-16 17:15:22 +00:00
feat: multi round palyback
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
||||
import { Button, Tooltip, message } from 'antd';
|
||||
import { GetServerSideProps, NextPage } from 'next';
|
||||
import Head from 'next/head';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types mirroring index.tsx
|
||||
@@ -347,9 +347,26 @@ function useReplayEngine(rounds: ReplayRound[], speed: number, autoPlay = false)
|
||||
for (let ri = stateRef.current.roundIndex; ri < rounds.length; ri++) {
|
||||
const round = rounds[ri];
|
||||
|
||||
// Restore already-finished rounds instantly
|
||||
// Skip already-finished rounds (defensive: if re-entered after restart)
|
||||
if (ri < stateRef.current.roundIndex) continue;
|
||||
|
||||
// If this round's final summary was already shown (e.g. runLoop restarted
|
||||
// after showing final but before advancing to next round), skip ahead.
|
||||
if (ri === stateRef.current.roundIndex && stateRef.current.showFinalForRound) {
|
||||
if (ri < rounds.length - 1) {
|
||||
await delay(BASE_DELAYS.betweenRounds);
|
||||
if (!playingRef.current) return;
|
||||
setState(prev => ({
|
||||
...prev,
|
||||
roundIndex: ri + 1,
|
||||
visibleStepCount: 0,
|
||||
activeStepId: null,
|
||||
showFinalForRound: false,
|
||||
}));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let si = stateRef.current.visibleStepCount; si < round.steps.length; si++) {
|
||||
if (!playingRef.current) return; // paused
|
||||
|
||||
@@ -485,7 +502,7 @@ const SharePage: NextPage<SharePageProps> = ({
|
||||
const [speed, setSpeed] = useState(1);
|
||||
const [rightPanelView, setRightPanelView] = useState<PanelView>('execution');
|
||||
|
||||
const rounds = initMessages ? buildReplayRounds(initMessages) : [];
|
||||
const rounds = useMemo(() => (initMessages ? buildReplayRounds(initMessages) : []), [initMessages]);
|
||||
const { state, playing, play, pause, jumpToRound, restart } = useReplayEngine(rounds, speed, true);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user