forked from EVOgeek/Vmeda.Online
		
	MOBILE-4287 quiz: Improve grace period UX
This commit is contained in:
		
							parent
							
								
									882cbb6473
								
							
						
					
					
						commit
						911bd6e749
					
				@ -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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user