MOBILE-4627 page: Don't download all files when opening

main
Dani Palou 2024-08-07 11:27:57 +02:00
parent 330b702cad
commit 8c566af484
3 changed files with 29 additions and 33 deletions

View File

@ -12,13 +12,6 @@
<core-course-module-info [module]="module" [description]="displayDescription && description" [component]="component"
[componentId]="componentId" [courseId]="courseId" (completionChanged)="onCompletionChange()" />
<ion-card class="core-warning-card" *ngIf="warning">
<ion-item>
<ion-icon name="fas-triangle-exclamation" slot="start" aria-hidden="true" />
<ion-label><span [innerHTML]="warning"></span></ion-label>
</ion-item>
</ion-card>
<div class="ion-padding">
<core-format-text [component]="component" [componentId]="componentId" [text]="contents" contextLevel="module"
[contextInstanceId]="module.id" [courseId]="courseId" />

View File

@ -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<void> {
// 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);
}
/**

View File

@ -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<CoreCourseModuleContentFile[]> {
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.
*