diff --git a/ui/analyse/src/study/practice/interfaces.ts b/ui/analyse/src/study/practice/interfaces.ts index 2582e835a59ff..5d80c147ed984 100644 --- a/ui/analyse/src/study/practice/interfaces.ts +++ b/ui/analyse/src/study/practice/interfaces.ts @@ -36,6 +36,7 @@ export interface StudyPracticeCtrl { onLoad(): void; onJump(): void; onCeval(): void; + onComplete(): void; data: StudyPracticeData; goal: Prop; success: Prop; diff --git a/ui/analyse/src/study/practice/studyPracticeCtrl.ts b/ui/analyse/src/study/practice/studyPracticeCtrl.ts index d41f3a4cb44fa..9859a2b12fb0c 100644 --- a/ui/analyse/src/study/practice/studyPracticeCtrl.ts +++ b/ui/analyse/src/study/practice/studyPracticeCtrl.ts @@ -3,11 +3,11 @@ import { Prop, prop } from 'common'; import { storedBooleanProp } from 'common/storage'; import makeSuccess from './studyPracticeSuccess'; import { readOnlyProp } from '../../util'; -import { StudyPracticeData, Goal } from './interfaces'; +import { StudyPracticeData, Goal, StudyPracticeCtrl } from './interfaces'; import { StudyData } from '../interfaces'; import AnalyseCtrl from '../../ctrl'; -export default class StudyPractice { +export default class StudyPractice implements StudyPracticeCtrl { goal: Prop; nbMoves = prop(0); // null = ongoing, true = win, false = fail @@ -55,12 +55,16 @@ export default class StudyPractice { }; onVictory = (): void => { - this.saveNbMoves(); site.sound.play('practiceSuccess'); + this.onComplete(); if (this.studyData.chapter.practice && this.autoNext()) setTimeout(this.root.study!.goToNextChapter, 1000); }; + onComplete = (): void => { + this.saveNbMoves(); + }; + saveNbMoves = (): void => { const chapterId = this.root.study!.currentChapter().id, former = this.data.completion[chapterId]; diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index 2992804cd619f..56f404d4c17c3 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -566,6 +566,7 @@ export default class StudyCtrl { if (chapter) this.setChapter(chapter.id); }; goToNextChapter = () => { + this.practice?.onComplete(); const chapter = this.nextChapter(); if (chapter) this.setChapter(chapter.id); };