MOBILE-4470 courses-storage: Update site size after delete data

main
Dani Palou 2024-05-22 16:18:51 +02:00
parent bb018c530f
commit 91c56256ed
1 changed files with 9 additions and 8 deletions

View File

@ -87,9 +87,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
} }
} }
this.spaceUsage = await CoreSettingsHelper.getSiteSpaceUsage(this.siteId); await this.setDownloadedCourses(downloadedCourses);
this.setDownloadedCourses(downloadedCourses);
this.loaded = true; this.loaded = true;
} }
@ -126,7 +124,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
try { try {
await Promise.all(deletedCourseIds.map((courseId) => CoreCourseHelper.deleteCourseFiles(courseId))); 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) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile')); CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
} finally { } finally {
@ -162,7 +160,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
try { try {
await CoreCourseHelper.deleteCourseFiles(course.id); await CoreCourseHelper.deleteCourseFiles(course.id);
this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course)); await this.setDownloadedCourses(CoreArray.withoutItem(this.downloadedCourses, course));
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile')); CoreDomUtils.showErrorModalDefault(error, Translate.instant('core.errordeletefile'));
} finally { } finally {
@ -177,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
*/ */
private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> { private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> {
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.setDownloadedCourses([]); await this.setDownloadedCourses([]);
return; return;
} }
@ -191,7 +189,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
course.isDownloading = status === DownloadStatus.DOWNLOADING; course.isDownloading = status === DownloadStatus.DOWNLOADING;
course.totalSize = await this.calculateDownloadedCourseSize(course.id); 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. * @param courses Courses info.
*/ */
private setDownloadedCourses(courses: DownloadedCourse[]): void { private async setDownloadedCourses(courses: DownloadedCourse[]): Promise<void> {
// 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.downloadedCourses = courses.sort((a, b) => b.totalSize - a.totalSize);
this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading); this.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading);
this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0); this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0);