diff --git a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html index 07c5b2027..6f10e6e92 100644 --- a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html +++ b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html @@ -3,20 +3,6 @@

{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}

-
- - - - - {{prefetchCoursesData.badge}} - - - -
-
@@ -25,7 +11,8 @@ -
+
diff --git a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index 4d31b6553..f55b37aea 100644 --- a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit, OnDestroy, Input, OnChanges, SimpleChange } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input } from '@angular/core'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { @@ -22,12 +22,10 @@ import { CoreCourseSummaryData, } from '@features/courses/services/courses'; import { CoreCourseSearchedDataWithExtraInfoAndOptions, CoreCoursesHelper } from '@features/courses/services/courses-helper'; -import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; import { AddonCourseCompletion } from '@/addons/coursecompletion/services/coursecompletion'; import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component'; import { CoreUtils } from '@services/utils/utils'; -import { CoreDomUtils } from '@services/utils/dom'; /** * Component to render a recent courses block. @@ -36,24 +34,15 @@ import { CoreDomUtils } from '@services/utils/dom'; selector: 'addon-block-recentlyaccessedcourses', templateUrl: 'addon-block-recentlyaccessedcourses.html', }) -export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnChanges, OnDestroy { +export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy { @Input() downloadEnabled = false; courses: (Omit & CoreCourseSearchedDataWithExtraInfoAndOptions)[] = []; - prefetchCoursesData: CorePrefetchStatusInfo = { - icon: '', - statusTranslatable: 'core.loading', - status: '', - loading: true, - badge: '', - }; downloadCourseEnabled = false; - downloadCoursesEnabled = false; scrollElementId!: string; - protected prefetchIconsInitialized = false; protected isDestroyed = false; protected coursesObserver?: CoreEventObserver; protected updateSiteObserver?: CoreEventObserver; @@ -74,12 +63,10 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom // Refresh the enabled flags if enabled. this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); // Refresh the enabled flags if site is updated. this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); }, CoreSites.getCurrentSiteId()); @@ -94,16 +81,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom super.ngOnInit(); } - /** - * @inheritdoc - */ - ngOnChanges(changes: {[name: string]: SimpleChange}): void { - if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) { - // Download all courses is enabled now, initialize it. - this.initPrefetchCoursesIcons(); - } - } - /** * @inheritdoc */ @@ -136,9 +113,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(','))); } - await CoreUtils.allPromises(promises).finally(() => { - this.prefetchIconsInitialized = false; - }); + await CoreUtils.allPromises(promises); } /** @@ -172,22 +147,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom }); await CoreCoursesHelper.loadCoursesColorAndImage(courses); - - this.initPrefetchCoursesIcons(); - } - - /** - * Initialize the prefetch icon for selected courses. - */ - protected async initPrefetchCoursesIcons(): Promise { - if (this.prefetchIconsInitialized || !this.downloadEnabled) { - // Already initialized. - return; - } - - this.prefetchIconsInitialized = true; - - this.prefetchCoursesData = await CoreCourseHelper.initPrefetchCoursesIcons(this.courses, this.prefetchCoursesData); } /** @@ -221,26 +180,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom data.state == CoreCoursesProvider.STATE_FAVOURITE && course) { course.isfavourite = !!data.value; await this.invalidateCourses([course.id]); - - this.initPrefetchCoursesIcons(); - } - } - - /** - * Prefetch all the shown courses. - * - * @return Promise resolved when done. - */ - async prefetchCourses(): Promise { - const initialIcon = this.prefetchCoursesData.icon; - - try { - await CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData); - } catch (error) { - if (!this.isDestroyed) { - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); - this.prefetchCoursesData.icon = initialIcon; - } } } diff --git a/src/addons/block/starredcourses/components/starredcourses/addon-block-starredcourses.html b/src/addons/block/starredcourses/components/starredcourses/addon-block-starredcourses.html index 8de46a904..3697b8439 100644 --- a/src/addons/block/starredcourses/components/starredcourses/addon-block-starredcourses.html +++ b/src/addons/block/starredcourses/components/starredcourses/addon-block-starredcourses.html @@ -3,20 +3,6 @@

{{ 'addon.block_starredcourses.pluginname' | translate }}

-
- - - - - {{prefetchCoursesData.badge}} - - - -
-
diff --git a/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts b/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts index 766c695c7..38fd77081 100644 --- a/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts +++ b/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts @@ -12,17 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit, OnDestroy, Input, OnChanges, SimpleChange } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input } from '@angular/core'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreCoursesProvider, CoreCoursesMyCoursesUpdatedEventData, CoreCourses } from '@features/courses/services/courses'; import { CoreCoursesHelper, CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper'; -import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; import { AddonCourseCompletion } from '@/addons/coursecompletion/services/coursecompletion'; import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component'; import { CoreUtils } from '@services/utils/utils'; -import { CoreDomUtils } from '@services/utils/dom'; /** * Component to render a starred courses block. @@ -31,24 +29,15 @@ import { CoreDomUtils } from '@services/utils/dom'; selector: 'addon-block-starredcourses', templateUrl: 'addon-block-starredcourses.html', }) -export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnChanges, OnDestroy { +export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy { @Input() downloadEnabled = false; courses: CoreEnrolledCourseDataWithOptions [] = []; - prefetchCoursesData: CorePrefetchStatusInfo = { - icon: '', - statusTranslatable: 'core.loading', - status: '', - loading: true, - badge: '', - }; downloadCourseEnabled = false; - downloadCoursesEnabled = false; scrollElementId!: string; - protected prefetchIconsInitialized = false; protected isDestroyed = false; protected coursesObserver?: CoreEventObserver; protected updateSiteObserver?: CoreEventObserver; @@ -69,12 +58,10 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im // Refresh the enabled flags if enabled. this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); // Refresh the enabled flags if site is updated. this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); }, CoreSites.getCurrentSiteId()); this.coursesObserver = CoreEvents.on( @@ -89,16 +76,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im super.ngOnInit(); } - /** - * @inheritdoc - */ - ngOnChanges(changes: {[name: string]: SimpleChange}): void { - if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) { - // Download all courses is enabled now, initialize it. - this.initPrefetchCoursesIcons(); - } - } - /** * @inheritdoc */ @@ -131,9 +108,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(','))); } - await CoreUtils.allPromises(promises).finally(() => { - this.prefetchIconsInitialized = false; - }); + await CoreUtils.allPromises(promises); } /** @@ -145,8 +120,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im // @TODO: Sort won't coincide with website because timemodified is not informed. this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('timemodified', 0, 'isfavourite', showCategories); - - this.initPrefetchCoursesIcons(); } /** @@ -182,43 +155,10 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im } await this.invalidateCourses([course.id]); - this.initPrefetchCoursesIcons(); } } - /** - * Initialize the prefetch icon for selected courses. - */ - protected async initPrefetchCoursesIcons(): Promise { - if (this.prefetchIconsInitialized || !this.downloadEnabled) { - // Already initialized. - return; - } - - this.prefetchIconsInitialized = true; - - this.prefetchCoursesData = await CoreCourseHelper.initPrefetchCoursesIcons(this.courses, this.prefetchCoursesData); - } - - /** - * Prefetch all the shown courses. - * - * @return Promise resolved when done. - */ - async prefetchCourses(): Promise { - const initialIcon = this.prefetchCoursesData.icon; - - try { - return CoreCourseHelper.prefetchCourses(this.courses, this.prefetchCoursesData); - } catch (error) { - if (!this.isDestroyed) { - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); - this.prefetchCoursesData.icon = initialIcon; - } - } - } - /** * @inheritdoc */