fixed issues

This commit is contained in:
2026-02-08 18:13:32 +01:00
parent f7401fb319
commit 1398682407
+10 -15
View File
@@ -48,28 +48,23 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) {
[run], [run],
); );
const [lastMoveId, setLastMoveId] = useState<number>(-1); const [_, setLastMoveId] = useState<number>(-1);
const [moves, setMoves] = useState<LiveRunMove[]>([]); const [moves, setMoves] = useState<LiveRunMove[]>([]);
useEffect(() => { useEffect(() => {
let moves = rawMoves?.filter((move) => move.moveId > lastMoveId) || []; if (!rawMoves || rawMoves.length === 0) return;
if (moves.length === 0) return; setLastMoveId((prevLastMoveId) => {
const newMoves = rawMoves.filter((move) => move.moveId > prevLastMoveId);
setMoves(moves); if (newMoves.length === 0) return prevLastMoveId;
setLastMoveId(lastMoveId + moves.length);
if (rawMoves?.length || 0 > 0) { setMoves(newMoves);
console.log("raw", rawMoves);
} return Math.max(...newMoves.map((m) => m.moveId));
});
}, [rawMoves]); }, [rawMoves]);
useEffect(() => {
if (moves.length > 0) {
console.log("moves", moves);
}
}, [moves]);
useEffect(() => { useEffect(() => {
if (!editorView || !moves) return; if (!editorView || !moves) return;
@@ -81,7 +76,7 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) {
if (!editorView || cancelled) return resolve(); if (!editorView || cancelled) return resolve();
editorView.dispatch({ editorView.dispatch({
// selection: { anchor: move.cursor }, selection: { anchor: move.cursor },
scrollIntoView: true, scrollIntoView: true,
changes: move.changes, changes: move.changes,
}); });