Merge pull request #3642 from NoelDeMartin/MOBILE-4287

MOBILE-4287 quiz: Improve grace period UX
main
Dani Palou 2023-04-25 17:14:25 +02:00 committed by GitHub
commit cfaa844414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 7 deletions

View File

@ -140,10 +140,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
* @inheritdoc
*/
ngOnDestroy(): void {
// Stop auto save.
this.autoSave.cancelAutoSave();
this.autoSave.stopCheckChangesProcess();
this.autoSaveErrorSubscription?.unsubscribe();
this.stopAutoSave();
if (this.quiz) {
// Unblock the quiz so it can be synced.
@ -423,9 +420,18 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
CoreEvents.trigger(CoreEvents.ACTIVITY_DATA_SENT, { module: 'quiz' });
// Leave the player.
this.forceLeave = true;
CoreNavigator.back();
if (!timeUp || !this.quiz.graceperiod) {
// Leave the player.
this.forceLeave = true;
CoreNavigator.back();
} else {
// Stay in player to show summary.
this.stopAutoSave();
this.clearTimer();
await this.refreshAttempt();
await this.loadSummary();
}
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_quiz.errorsaveattempt', true);
} finally {
@ -495,6 +501,13 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
}
}
/**
* Remove timer info.
*/
protected clearTimer(): void {
delete this.endTime;
}
/**
* Load a page questions.
*
@ -542,6 +555,22 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
this.autoSave.startCheckChangesProcess(this.quiz, this.attempt, this.preflightData, this.offline);
}
/**
* Refresh attempt data.
*/
protected async refreshAttempt(): Promise<void> {
if (!this.quiz) {
return;
}
const attempts = await AddonModQuiz.getUserAttempts(this.quiz.id, {
cmId: this.quiz.coursemodule,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PREFER_CACHE : CoreSitesReadingStrategy.ONLY_NETWORK,
});
this.attempt = attempts.find(attempt => attempt.id === this.attempt?.id);
}
/**
* Load attempt summary.
*
@ -810,6 +839,15 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
this.finishAttempt(false, true);
}
/**
* Stop auto-saving answers.
*/
protected stopAutoSave(): void {
this.autoSave.cancelAutoSave();
this.autoSave.stopCheckChangesProcess();
this.autoSaveErrorSubscription?.unsubscribe();
}
}
/**