From d42bbdf2ca5001020dc4e64b70ccb14ac12b5254 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 16 Mar 2022 14:11:17 +0100 Subject: [PATCH] MOBILE-3930 course: Mark site plugins as module viewed --- .../components/module-index/module-index.ts | 12 ++++++++---- .../components/plugin-content/plugin-content.ts | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/features/siteplugins/components/module-index/module-index.ts b/src/core/features/siteplugins/components/module-index/module-index.ts index bbaebb0d2..a0001552f 100644 --- a/src/core/features/siteplugins/components/module-index/module-index.ts +++ b/src/core/features/siteplugins/components/module-index/module-index.ts @@ -21,6 +21,7 @@ import { CoreCourseModuleSummaryResult, CoreCourseModuleSummaryComponent, } from '@features/course/components/module-summary/module-summary'; +import { CoreCourse } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate, @@ -35,7 +36,7 @@ import { import { IonRefresher } from '@ionic/angular'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; -import { CoreSitePluginsPluginContentComponent } from '../plugin-content/plugin-content'; +import { CoreSitePluginsPluginContentComponent, CoreSitePluginsPluginContentLoadedData } from '../plugin-content/plugin-content'; /** * Component that displays the index of a module site plugin. @@ -161,9 +162,12 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C /** * Function called when the data of the site plugin content is loaded. */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - contentLoaded(refresh: boolean): void { - return; + contentLoaded(data: CoreSitePluginsPluginContentLoadedData): void { + if (data.success) { + CoreCourse.storeModuleViewed(this.courseId, this.module.id, { + sectionId: this.module.section, + }); + } } /** diff --git a/src/core/features/siteplugins/components/plugin-content/plugin-content.ts b/src/core/features/siteplugins/components/plugin-content/plugin-content.ts index ce4c7e2d9..1704e3cff 100644 --- a/src/core/features/siteplugins/components/plugin-content/plugin-content.ts +++ b/src/core/features/siteplugins/components/plugin-content/plugin-content.ts @@ -43,7 +43,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck { @Input() data?: Record; // Data to pass to the component. @Input() preSets?: CoreSiteWSPreSets; // The preSets for the WS call. @Input() pageTitle?: string; // Current page title. It can be used by the "new-content" directives. - @Output() onContentLoaded = new EventEmitter(); // Emits an event when the content is loaded. + @Output() onContentLoaded = new EventEmitter(); // Emits event when content is loaded. @Output() onLoadingContent = new EventEmitter(); // Emits an event when starts to load the content. content?: string; // Content. @@ -114,11 +114,11 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck { this.jsData.updateContent = this.updateContent.bind(this); this.jsData.updateModuleCourseContent = this.updateModuleCourseContent.bind(this); - this.onContentLoaded.emit(refresh); + this.onContentLoaded.emit({ refresh: !!refresh, success: true }); } catch (error) { // Make it think it's loaded - otherwise it sticks on 'loading' and stops navigation working. this.content = '
'; - this.onContentLoaded.emit(refresh); + this.onContentLoaded.emit({ refresh: !!refresh, success: false }); CoreDomUtils.showErrorModalDefault(error, 'core.errorloadingcontent', true); } finally { @@ -237,3 +237,8 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck { } } + +export type CoreSitePluginsPluginContentLoadedData = { + refresh: boolean; + success: boolean; +};