Skip to content

Commit

Permalink
MOBILE-4470 courses-storage: Update site size after delete data
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed May 22, 2024
1 parent bb018c5 commit 91c5625
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -177,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
*/
private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise<void> {
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.setDownloadedCourses([]);
await this.setDownloadedCourses([]);

return;
}
Expand All @@ -191,15 +189,18 @@ 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);
}

/**
* Set downloaded courses data.
*
* @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.completelyDownloadedCourses = courses.filter((course) => !course.isDownloading);
this.totalSize = this.downloadedCourses.reduce((totalSize, course) => totalSize + course.totalSize, 0);
Expand Down

0 comments on commit 91c5625

Please sign in to comment.