diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts index e118ab127..9e1a3f9b5 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts @@ -87,9 +87,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy } } - this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId); - - this.setDownloadedCourses(downloadedCourses); + await this.setDownloadedCourses(downloadedCourses); this.loaded = true; } @@ -126,7 +124,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy try { await Promise.all(deletedCourseIds.map((courseId) => CoreCourseHelper.deleteCourseFiles(courseId))); - this.setDownloadedCourses(this.downloadedCourses.filter((course) => !deletedCourseIds.includes(course.id))); + await this.setDownloadedCourses(this.downloadedCourses.filter((course) => !deletedCourseIds.includes(course.id))); } catch (error) { CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile')); } finally { @@ -162,7 +160,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy try { await CoreCourseHelper.deleteCourseFiles(course.id); - this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course)); + await this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course)); } catch (error) { CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile')); } finally { @@ -177,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy */ private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise { if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { - this.setDownloadedCourses([]); + await this.setDownloadedCourses([]); return; } @@ -191,7 +189,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy course.isDownloading = status === DownloadStatus.DOWNLOADING; course.totalSize = await this.calculateDownloadedCourseSize(course.id); - this.setDownloadedCourses(this.downloadedCourses); + await this.setDownloadedCourses(this.downloadedCourses); } /** @@ -199,7 +197,10 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy * * @param courses Courses info. */ - private setDownloadedCourses(courses: DownloadedCourse[]): void { + private async setDownloadedCourses(courses: DownloadedCourse[]): Promise { + // Downloaded courses changed, update site usage too. + this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId); + this.downloadedCourses = courses.sort((a, b) => b.totalSize - a.totalSize); this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading); this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0); diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index e4c7fae9f..a790499db 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -99,6 +99,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec protected emptyText = ''; protected domPromises: CoreCancellablePromise[] = []; protected domElementPromise?: CoreCancellablePromise; + protected externalContentInstances: CoreExternalContentDirective[] = []; constructor( element: ElementRef, @@ -145,6 +146,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec this.domElementPromise?.cancel(); this.domPromises.forEach((promise) => { promise.cancel();}); this.elementControllers.forEach(controller => controller.destroy()); + this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy()); } /** @@ -191,6 +193,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec extContent.ngAfterViewInit(); + this.externalContentInstances.push(extContent); + const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef); changeDetectorRef.markForCheck(); @@ -342,6 +346,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec * Format contents and render. */ protected async formatAndRenderContents(): Promise { + // Destroy previous instances of external-content. + this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy()); + this.externalContentInstances = []; + if (!this.text) { this.element.innerHTML = this.emptyText; // Remove current contents. diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index dce4f5be3..814db49c1 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -1912,12 +1912,14 @@ export class CoreCourseHelperProvider { * @returns Promise to be resolved once the course files are deleted. */ async deleteCourseFiles(courseId: number): Promise { + const siteId = CoreSites.getCurrentSiteId(); const sections = await CoreCourse.getSections(courseId); const modules = sections.map((section) => section.modules).flat(); - await Promise.all( - modules.map((module) => this.removeModuleStoredData(module, courseId)), - ); + await Promise.all([ + ...modules.map((module) => this.removeModuleStoredData(module, courseId)), + siteId && CoreFilepool.removeFilesByComponent(siteId, CoreCourseProvider.COMPONENT, courseId), + ]); await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED); }