From 51661054edf379e4f7c87bb23d46afdfd5c2d866 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 3 Jun 2021 17:00:17 +0200 Subject: [PATCH] MOBILE-3320 course: Fix progress bar reactivity --- .../course/components/format/format.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/features/course/components/format/format.ts b/src/core/features/course/components/format/format.ts index 389abc1f5..e03ca79a2 100644 --- a/src/core/features/course/components/format/format.ts +++ b/src/core/features/course/components/format/format.ts @@ -191,8 +191,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.displaySectionSelector = CoreCourseFormatDelegate.displaySectionSelector(this.course); this.displayBlocks = CoreCourseFormatDelegate.displayBlocks(this.course); - this.progress = 'progress' in this.course && typeof this.course.progress == 'number' && - this.course.progress >= 0 && this.course.completionusertracked !== false ? this.course.progress : undefined; + this.updateProgress(); + if ('overviewfiles' in this.course) { this.imageThumb = this.course.overviewfiles?.[0]?.fileurl; } @@ -641,6 +641,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { } else { this.course.progress = Math.max(0, this.course.progress - moduleProgressPercent); } + + this.updateProgress(); } /** @@ -654,4 +656,23 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); } + /** + * Update course progress. + */ + protected updateProgress(): void { + if ( + !this.course || + !('progress' in this.course) || + typeof this.course.progress !== 'number' || + this.course.progress < 0 || + this.course.completionusertracked === false + ) { + this.progress = undefined; + + return; + } + + this.progress = this.course.progress; + } + }