From 911bd6e749b41c9c6dc069b92808d17b27fe0c3d Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 25 Apr 2023 12:25:53 +0200 Subject: [PATCH] MOBILE-4287 quiz: Improve grace period UX --- src/addons/mod/quiz/pages/player/player.ts | 52 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/src/addons/mod/quiz/pages/player/player.ts b/src/addons/mod/quiz/pages/player/player.ts index c44d5119c..273350446 100644 --- a/src/addons/mod/quiz/pages/player/player.ts +++ b/src/addons/mod/quiz/pages/player/player.ts @@ -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 { + 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(); + } + } /**