diff --git a/src/addons/mod/book/components/index/index.ts b/src/addons/mod/book/components/index/index.ts index 09263edda..e711670ba 100644 --- a/src/addons/mod/book/components/index/index.ts +++ b/src/addons/mod/book/components/index/index.ts @@ -18,6 +18,7 @@ import { AddonModBook, AddonModBookBookWSData, AddonModBookNumbering, AddonModBo import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; +import { CoreUtils } from '@services/utils/utils'; /** * Component that displays a book entry page. @@ -47,6 +48,9 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp super.ngOnInit(); this.loadContent(); + + // Log book viewed. + await CoreUtils.ignoreErrors(AddonModBook.logView(this.module.instance, undefined, this.module.name)); } /** diff --git a/src/addons/mod/book/pages/contents/contents.ts b/src/addons/mod/book/pages/contents/contents.ts index 7a2055bd3..1f8ebb2b9 100644 --- a/src/addons/mod/book/pages/contents/contents.ts +++ b/src/addons/mod/book/pages/contents/contents.ts @@ -69,7 +69,6 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { loaded = false; - protected firstLoad = true; protected managerUnsubscribe?: () => void; /** @@ -272,10 +271,6 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { * @return Promise resolved when done. */ protected async onChapterViewed(chapterId: number): Promise { - // Don't log the chapter ID when the user has just opened the book. - const logChapterId = this.firstLoad; - this.firstLoad = false; - if (this.displayNavBar) { this.navigationItems = this.getNavigationItems(chapterId); } @@ -289,11 +284,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { } // Chapter loaded, log view. - await CoreUtils.ignoreErrors(AddonModBook.logView( - this.module.instance, - logChapterId ? chapterId : undefined, - this.module.name, - )); + await CoreUtils.ignoreErrors(AddonModBook.logView(this.module.instance, chapterId, this.module.name)); const currentChapterIndex = this.chapters.findIndex((chapter) => chapter.id == chapterId); const isLastChapter = currentChapterIndex < 0 || this.chapters[currentChapterIndex + 1] === undefined;