diff --git a/src/addons/mod/page/components/index/addon-mod-page-index.html b/src/addons/mod/page/components/index/addon-mod-page-index.html index 2f82a39e6..d6978007d 100644 --- a/src/addons/mod/page/components/index/addon-mod-page-index.html +++ b/src/addons/mod/page/components/index/addon-mod-page-index.html @@ -12,13 +12,6 @@ - - - - -
diff --git a/src/addons/mod/page/components/index/index.ts b/src/addons/mod/page/components/index/index.ts index fcef8de3f..5e78527f1 100644 --- a/src/addons/mod/page/components/index/index.ts +++ b/src/addons/mod/page/components/index/index.ts @@ -15,7 +15,6 @@ import { Component, OnInit, Optional } from '@angular/core'; import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; -import { CoreCourse } from '@features/course/services/course'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; import { AddonModPagePage, AddonModPage } from '../../services/page'; @@ -38,7 +37,6 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp displayTimemodified = true; timemodified?: number; page?: AddonModPagePage; - warning?: string; protected fetchContentDefaultError = 'addon.mod_page.errorwhileloadingthepage'; @@ -68,19 +66,12 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp * @inheritdoc */ protected async fetchContent(refresh?: boolean): Promise { - // Download the resource if it needs to be downloaded. - const downloadResult = await this.downloadResourceIfNeeded(refresh); - - // Get contents. No need to refresh, it has been done in downloadResourceIfNeeded. - const contents = await CoreCourse.getModuleContents(this.module); - - const results = await Promise.all([ + const [contents] = await Promise.all([ + this.getModuleContents(refresh), this.loadPageData(), - AddonModPageHelper.getPageHtml(contents, this.module.id), ]); - this.contents = results[1]; - this.warning = downloadResult?.failed ? this.getErrorDownloadingSomeFilesMessage(downloadResult.error!) : ''; + this.contents = await AddonModPageHelper.getPageHtml(contents, this.module.id); } /** diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 40a2e7cda..6434c503b 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -26,7 +26,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; import { CoreCourseModuleSummaryResult } from '../components/module-summary/module-summary'; import { CoreCourseContentsPage } from '../pages/contents/contents'; -import { CoreCourse } from '../services/course'; +import { CoreCourse, CoreCourseModuleContentFile } from '../services/course'; import { CoreCourseHelper, CoreCourseModuleData } from '../services/course-helper'; import { CoreCourseModuleDelegate, CoreCourseModuleMainComponent } from '../services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate'; @@ -364,24 +364,36 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) { // Try to load the contents. - const ignoreCache = refresh && CoreNetwork.isOnline(); - - try { - await CoreCourse.loadModuleContents(this.module, undefined, undefined, false, ignoreCache); - } catch (error) { - // Error loading contents. If we ignored cache, try to get the cached value. - if (ignoreCache && !this.module.contents) { - await CoreCourse.loadModuleContents(this.module); - } else if (!this.module.contents) { - // Not able to load contents, throw the error. - throw error; - } - } + await this.getModuleContents(refresh); } return result; } + /** + * Get module contents. + * + * @param refresh Whether we're refreshing data. + * @returns Module contents. + */ + protected async getModuleContents(refresh?: boolean): Promise { + const ignoreCache = refresh && CoreNetwork.isOnline(); + + try { + return await CoreCourse.getModuleContents(this.module, undefined, undefined, false, ignoreCache); + } catch (error) { + // Error loading contents. If we ignored cache, try to get the cached value. + if (ignoreCache && !this.module.contents) { + return await CoreCourse.getModuleContents(this.module); + } else if (!this.module.contents) { + // Not able to load contents, throw the error. + throw error; + } + + return this.module.contents; + } + } + /** * The completion of the modules has changed. *