Merge pull request #3490 from alfonso-salces/MOBILE-4085
MOBILE-4085 course-storage: Add change detection OnPushmain
commit
140493b43b
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
|
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
|
||||||
import {
|
import {
|
||||||
CoreCourseHelper,
|
CoreCourseHelper,
|
||||||
|
@ -41,6 +41,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
selector: 'page-addon-storagemanager-course-storage',
|
selector: 'page-addon-storagemanager-course-storage',
|
||||||
templateUrl: 'course-storage.html',
|
templateUrl: 'course-storage.html',
|
||||||
styleUrls: ['course-storage.scss'],
|
styleUrls: ['course-storage.scss'],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
protected isDestroyed = false;
|
protected isDestroyed = false;
|
||||||
protected isGuest = false;
|
protected isGuest = false;
|
||||||
|
|
||||||
constructor(protected elementRef: ElementRef) {
|
constructor(protected elementRef: ElementRef, protected changeDetectorRef: ChangeDetectorRef) {
|
||||||
// Refresh the enabled flags if site is updated.
|
// Refresh the enabled flags if site is updated.
|
||||||
this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
||||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||||
|
@ -79,7 +80,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.initCoursePrefetch();
|
this.initCoursePrefetch();
|
||||||
this.initModulePrefetch();
|
this.initModulePrefetch();
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}, CoreSites.getCurrentSiteId());
|
}, CoreSites.getCurrentSiteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
this.initCoursePrefetch(),
|
this.initCoursePrefetch(),
|
||||||
this.initModulePrefetch(),
|
this.initModulePrefetch(),
|
||||||
]);
|
]);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,12 +314,13 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.calculatingSize = true;
|
module.calculatingSize = true;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
|
|
||||||
if (!section) {
|
if (!section) {
|
||||||
section = this.sections.find((section) => section.modules.some((mod) => mod.id === module.id));
|
section = this.sections.find((section) => section.modules.some((mod) => mod.id === module.id));
|
||||||
if (section) {
|
if (section) {
|
||||||
section.calculatingSize = true;
|
section.calculatingSize = true;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +338,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
// Ignore errors, it shouldn't happen.
|
// Ignore errors, it shouldn't happen.
|
||||||
} finally {
|
} finally {
|
||||||
module.calculatingSize = false;
|
module.calculatingSize = false;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -344,7 +346,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
if (section) {
|
if (section) {
|
||||||
section.calculatingSize = false;
|
section.calculatingSize = false;
|
||||||
}
|
}
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -490,7 +492,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
await this.updateModulesSizes(modules, section);
|
await this.updateModulesSizes(modules, section);
|
||||||
CoreCourseHelper.calculateSectionsStatus(this.sections, this.courseId, false, false);
|
CoreCourseHelper.calculateSectionsStatus(this.sections, this.courseId, false, false);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +527,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
async prefecthSection(section: AddonStorageManagerCourseSection): Promise<void> {
|
async prefecthSection(section: AddonStorageManagerCourseSection): Promise<void> {
|
||||||
section.isCalculating = true;
|
section.isCalculating = true;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
try {
|
try {
|
||||||
await CoreCourseHelper.confirmDownloadSizeSection(this.courseId, section, this.sections);
|
await CoreCourseHelper.confirmDownloadSizeSection(this.courseId, section, this.sections);
|
||||||
|
|
||||||
|
@ -538,18 +540,19 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
await this.updateModulesSizes(section.modules, section);
|
await this.updateModulesSizes(section.modules, section);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// User cancelled or there was an error calculating the size.
|
// User cancelled or there was an error calculating the size.
|
||||||
if (!this.isDestroyed && error) {
|
if (!this.isDestroyed && error) {
|
||||||
CoreDomUtils.showErrorModal(error);
|
CoreDomUtils.showErrorModal(error);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
section.isCalculating = false;
|
section.isCalculating = false;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,7 +609,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
module.downloadStatus = status;
|
module.downloadStatus = status;
|
||||||
|
|
||||||
module.handlerData?.updateStatus?.(status);
|
module.handlerData?.updateStatus?.(status);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -646,7 +649,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
this.prefetchCourseData.icon = statusData.icon;
|
this.prefetchCourseData.icon = statusData.icon;
|
||||||
this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
|
this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
|
||||||
this.prefetchCourseData.loading = statusData.loading;
|
this.prefetchCourseData.loading = statusData.loading;
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -668,7 +671,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
await CoreCourseHelper.confirmAndPrefetchCourse(
|
await CoreCourseHelper.confirmAndPrefetchCourse(
|
||||||
this.prefetchCourseData,
|
this.prefetchCourseData,
|
||||||
course,
|
course,
|
||||||
|
@ -677,7 +680,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
|
||||||
isGuest: this.isGuest,
|
isGuest: this.isGuest,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
this.changeDetectorRef.markForCheck();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.isDestroyed) {
|
if (this.isDestroyed) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue