Merge pull request #2956 from dpalou/MOBILE-3877

MOBILE-3877 quiz: Fix review not opened after finish offline quiz
main
Noel De Martin 2021-09-23 17:56:21 +02:00 committed by GitHub
commit 3fa0136cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View File

@ -208,7 +208,8 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
await AddonModQuizSync.setSyncWarnings(quiz.id, []); await AddonModQuizSync.setSyncWarnings(quiz.id, []);
} }
if (AddonModQuiz.isQuizOffline(quiz) && sync) { if (AddonModQuiz.isQuizOffline(quiz)) {
if (sync) {
// Try to sync the quiz. // Try to sync the quiz.
try { try {
await this.syncActivity(showErrors); await this.syncActivity(showErrors);
@ -216,6 +217,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
// Ignore errors, keep getting data even if sync fails. // Ignore errors, keep getting data even if sync fails.
this.autoReview = undefined; this.autoReview = undefined;
} }
}
} else { } else {
this.autoReview = undefined; this.autoReview = undefined;
this.showStatusSpinner = false; this.showStatusSpinner = false;

View File

@ -664,11 +664,21 @@ export class AddonModQuizProvider {
/** /**
* Given a list of attempts, returns the last finished attempt. * Given a list of attempts, returns the last finished attempt.
* *
* @param attempts Attempts. * @param attempts Attempts sorted. First attempt should be the first on the list.
* @return Last finished attempt. * @return Last finished attempt.
*/ */
getLastFinishedAttemptFromList(attempts?: AddonModQuizAttemptWSData[]): AddonModQuizAttemptWSData | undefined { getLastFinishedAttemptFromList(attempts?: AddonModQuizAttemptWSData[]): AddonModQuizAttemptWSData | undefined {
return attempts?.find(attempt => this.isAttemptFinished(attempt.state)); if (!attempts) {
return;
}
for (let i = attempts.length - 1; i >= 0; i--) {
const attempt = attempts[i];
if (this.isAttemptFinished(attempt.state)) {
return attempt;
}
}
} }
/** /**