MOBILE-3877 quiz: Fix review not opened after finish offline quiz

main
Dani Palou 2021-09-23 12:01:00 +02:00
parent 14c019c268
commit aa6824e495
2 changed files with 21 additions and 9 deletions

View File

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

View File

@ -664,11 +664,21 @@ export class AddonModQuizProvider {
/**
* 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.
*/
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;
}
}
}
/**