diff --git a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index bea1cc104..f786edbc2 100644 --- a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -221,7 +221,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom const initialIcon = this.prefetchCoursesData.icon; try { - return CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData); + await CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData); } catch (error) { if (!this.isDestroyed) { CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 7e7dcd319..c1d217392 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -374,42 +374,45 @@ export class CoreCourseHelperProvider { menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[], ): Promise { const initialIcon = data.icon; - const initialStatus = data.statusTranslatable; + const initialStatus = data.status; + const initialStatusTranslatable = data.statusTranslatable; const siteId = CoreSites.getCurrentSiteId(); data.downloadSucceeded = false; data.icon = CoreConstants.ICON_DOWNLOADING; + data.status = CoreConstants.DOWNLOADING; data.statusTranslatable = 'core.downloading'; - // Get the sections first if needed. - if (!sections) { - sections = await CoreCourse.getSections(course.id, false, true); - } - try { + // Get the sections first if needed. + if (!sections) { + sections = await CoreCourse.getSections(course.id, false, true); + } + // Confirm the download. await this.confirmDownloadSizeSection(course.id, undefined, sections, true); + + // User confirmed, get the course handlers if needed. + if (!courseHandlers) { + courseHandlers = await CoreCourseOptionsDelegate.getHandlersToDisplay(course); + } + if (!menuHandlers) { + menuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course); + } + + // Now we have all the data, download the course. + await this.prefetchCourse(course, sections, courseHandlers, menuHandlers, siteId); + + // Download successful. + data.downloadSucceeded = true; } catch (error) { - // User cancelled or there was an error calculating the size. + // User cancelled or there was an error. data.icon = initialIcon; - data.statusTranslatable = initialStatus; + data.status = initialStatus; + data.statusTranslatable = initialStatusTranslatable; throw error; } - - // User confirmed, get the course handlers if needed. - if (!courseHandlers) { - courseHandlers = await CoreCourseOptionsDelegate.getHandlersToDisplay(course); - } - if (!menuHandlers) { - menuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course); - } - - // Now we have all the data, download the course. - await this.prefetchCourse(course, sections, courseHandlers, menuHandlers, siteId); - - // Download successful. - data.downloadSucceeded = true; } /** diff --git a/src/core/features/courses/components/course-progress/core-courses-course-progress.html b/src/core/features/courses/components/course-progress/core-courses-course-progress.html index 9dd5128b4..33cd0cfd4 100644 --- a/src/core/features/courses/components/course-progress/core-courses-course-progress.html +++ b/src/core/features/courses/components/course-progress/core-courses-course-progress.html @@ -41,7 +41,7 @@ [statusTranslatable]="prefetchCourseData.statusTranslatable" canTrustDownload="false" [loading]="prefetchCourseData.loading" - action="prefetchCourse()"> + (action)="prefetchCourse()">
diff --git a/src/core/features/courses/components/course-progress/course-progress.ts b/src/core/features/courses/components/course-progress/course-progress.ts index 7109ad66c..2c4b9db69 100644 --- a/src/core/features/courses/components/course-progress/course-progress.ts +++ b/src/core/features/courses/components/course-progress/course-progress.ts @@ -107,8 +107,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy { // Determine course prefetch icon. const status = await CoreCourse.getCourseStatus(this.course.id); - this.prefetchCourseData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); - this.courseStatus = status; + this.updateCourseStatus(status); if (this.prefetchCourseData.loading) { // Course is being downloaded. Get the download promise.