MOBILE-3320 dashboard: Fix download issues in recent access courses

main
Dani Palou 2021-06-29 16:00:06 +02:00
parent 8797d3e56f
commit 9d471e94b8
4 changed files with 28 additions and 26 deletions

View File

@ -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);

View File

@ -374,42 +374,45 @@ export class CoreCourseHelperProvider {
menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[],
): Promise<void> {
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;
}
/**

View File

@ -41,7 +41,7 @@
[statusTranslatable]="prefetchCourseData.statusTranslatable"
canTrustDownload="false"
[loading]="prefetchCourseData.loading"
action="prefetchCourse()"></core-download-refresh>
(action)="prefetchCourse()"></core-download-refresh>
</div>
<div class="core-button-spinner" *ngIf="courseOptionMenuEnabled" slot="end">

View File

@ -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.