fixed issues
This commit is contained in:
@@ -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,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user