Skip to content

Commit

Permalink
Jump to correct move only if chapter has loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Carbrex committed Jul 7, 2024
1 parent 02ed544 commit accf84c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ui/analyse/src/study/relay/chatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@ export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler {
if (segs.length == 3) {
const [_, chapterId, ply] = segs;
ctrl.study.setChapter(chapterId);
setTimeout(() => ctrl.jumpToMain(parseInt(ply)), 100);

let attempts = 0;
const maxAttempts = 50;

// wait for the chapter to be set before jumping to the move
const waitForLoadingAndJump = () => {
if (!ctrl.study?.vm.loading) {
ctrl.jumpToMain(parseInt(ply));
} else if (attempts < maxAttempts) {
attempts++;
setTimeout(waitForLoadingAndJump, 100);
} else {
console.log('Failed to jump to move, took too many attempts.');
}
};

waitForLoadingAndJump();
}
}
};
Expand Down

0 comments on commit accf84c

Please sign in to comment.