Skip to content

Commit d124f2b

Browse files
committed
Use studyvm to go to a given move after chapter is fetched
1 parent 9ff3d6e commit d124f2b

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

ui/analyse/src/study/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface StudyVm {
2525
loading: boolean;
2626
nextChapterId?: ChapterId;
2727
justSetChapterId?: ChapterId;
28+
nextPly?: number;
2829
tab: Prop<Tab>;
2930
toolTab: Prop<ToolTab>;
3031
chapterId: ChapterId;

ui/analyse/src/study/relay/chatHandler.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,15 @@ export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler {
3232
const segs = msg.split(separator);
3333
if (segs.length == 3) {
3434
const [_, chapterId, ply] = segs;
35-
ctrl.study.setChapter(chapterId);
36-
37-
let attempts = 0;
38-
const maxAttempts = 50;
39-
40-
// wait for the chapter to be set before jumping to the move
41-
const waitForLoadingAndJump = () => {
42-
if (!ctrl.study?.vm.loading) {
43-
ctrl.jumpToMain(parseInt(ply));
44-
} else if (attempts < maxAttempts) {
45-
attempts++;
46-
setTimeout(waitForLoadingAndJump, 100);
47-
} else {
48-
console.log('Failed to jump to move, took too many attempts.');
35+
if (ctrl.study.vm.chapterId != chapterId || ctrl.study.vm.loading) {
36+
ctrl.study.vm.nextPly = parseInt(ply);
37+
ctrl.study.setChapter(chapterId);
38+
} else {
39+
if (ctrl.study.relay.tourShow()) {
40+
ctrl.study.relay.tourShow(false);
4941
}
50-
};
51-
52-
waitForLoadingAndJump();
42+
ctrl.jumpToMain(parseInt(ply));
43+
}
5344
}
5445
}
5546
};

ui/analyse/src/study/studyCtrl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,13 @@ export default class StudyCtrl {
364364
: this.data.chapter.relayPath || this.chapters.localPaths[this.vm.chapterId] || treePath.root;
365365
}
366366

367-
// path could be gone (because of subtree deletion), go as far as possible
368-
this.ctrl.userJump(this.ctrl.tree.longestValidPath(nextPath));
367+
if (this.vm.nextPly) {
368+
this.ctrl.jumpToMain(this.vm.nextPly);
369+
this.vm.nextPly = undefined;
370+
} else {
371+
// path could be gone (because of subtree deletion), go as far as possible
372+
this.ctrl.userJump(this.ctrl.tree.longestValidPath(nextPath));
373+
}
369374

370375
this.vm.justSetChapterId = undefined;
371376

0 commit comments

Comments
 (0)