From a69967007ae9960aa7cbdcb7b78bfb1a4d35d14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Oct 2024 10:38:50 +0200 Subject: [PATCH] MOBILE-4616 course: Fix change section from course index when mod opens --- .../components/course-format/course-format.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index ca29c70fe15..91c0f75260c 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -483,12 +483,15 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { id: data.moduleId === undefined ? data.sectionId : undefined, }); - // Select the root section. - this.sectionChanged(parents[0] ?? section); + // If a section is selected (no moduleId), or all sections are not displayed. Change section. + if (!data.moduleId || !this.selectedSection || this.selectedSection.id !== this.allSectionsId) { + // Select the root section. + this.sectionChanged(parents[0] ?? section); + } - if (parents.length && section) { - // It's a subsection. Expand all the parents and the subsection. - for (let i = 1; i < parents.length; i++) { + if (section) { + // It's a subsection. Expand its parents too. + for (let i = 0; i < parents.length; i++) { this.setSectionExpanded(parents[i]); } @@ -811,6 +814,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { */ accordionMultipleChange(ev: AccordionGroupChangeEventDetail): void { const sectionIds = ev.value as string[] | undefined; + + this.accordionMultipleValue = ev.value; + const allSections = CoreCourseHelper.flattenSections(this.sections); allSections.forEach((section) => { section.expanded = false; @@ -836,8 +842,14 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { */ protected setSectionExpanded(section: CoreCourseSectionToDisplay): void { section.expanded = true; + if (!this.accordionMultipleValue.includes(section.id.toString())) { - this.accordionMultipleValue.push(section.id.toString()); + // Force detect changes to update the view. + this.accordionMultipleValue = [ + ...this.accordionMultipleValue, + section.id.toString(), + ]; + this.saveExpandedSections(); } }