From 11dcd29435c40d80acce28c1fbdcb76a452de5c0 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Fri, 3 Jun 2022 13:39:26 +0200
Subject: [PATCH] [player] Send event about the presented pages when
 re-entering the unit

---
 .../player/src/app/services/unit-state.service.ts    | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/projects/player/src/app/services/unit-state.service.ts b/projects/player/src/app/services/unit-state.service.ts
index fc05fb6d6..c0a11e17b 100644
--- a/projects/player/src/app/services/unit-state.service.ts
+++ b/projects/player/src/app/services/unit-state.service.ts
@@ -108,18 +108,18 @@ export class UnitStateService {
       if (ElementCodeStatusValue[status] > ElementCodeStatusValue[unitStateElementCode.status]) {
         unitStateElementCode.status = status;
         this._elementCodeChanged.next(unitStateElementCode);
-        this.checkPresentedPageStatus(this.elementIdPageIndexMap[id], true);
+        this.checkPresentedPageStatus(this.elementIdPageIndexMap[id]);
       }
     }
   }
 
   private buildPresentedPages(): void {
     const uniqPages = [...new Set( Object.values(this.elementIdPageIndexMap))];
-    uniqPages.forEach((pageIndex, index) => this
-      .checkPresentedPageStatus(pageIndex, index === uniqPages.length - 1));
+    uniqPages.forEach(pageIndex => this
+      .checkPresentedPageStatus(pageIndex));
   }
 
-  private checkPresentedPageStatus(pageIndex: number, emitEvent: boolean): void {
+  private checkPresentedPageStatus(pageIndex: number): void {
     if (this.presentedPages.indexOf(pageIndex) === -1) {
       const notDisplayedElements = Object.entries(this.elementIdPageIndexMap)
         .filter((map: [string, number]): boolean => map[1] === pageIndex)
@@ -129,9 +129,7 @@ export class UnitStateService {
           ElementCodeStatusValue.DISPLAYED);
       if (notDisplayedElements.length === 0) {
         this.presentedPages.push(pageIndex);
-        if (emitEvent) {
-          this._presentedPageAdded.next(pageIndex);
-        }
+        this._presentedPageAdded.next(pageIndex);
       }
     } else {
       LogService.warn(`player: page ${pageIndex} is already presented`);
-- 
GitLab