From d8c644b1e219042cd15b1ac05df899d74c5c926f Mon Sep 17 00:00:00 2001
From: geireann <60007097+geireann@users.noreply.github.com>
Date: Tue, 1 Dec 2020 20:31:17 +0800
Subject: small changes to temp audio stopping (not final)

---
 src/client/views/nodes/PresBox.tsx | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

(limited to 'src/client/views/nodes/PresBox.tsx')

diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx
index e559b6ca3..d21e1603d 100644
--- a/src/client/views/nodes/PresBox.tsx
+++ b/src/client/views/nodes/PresBox.tsx
@@ -290,6 +290,12 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
             this.rootDoc._itemIndex = index;
             const activeItem: Doc = this.activeItem;
             const targetDoc: Doc = this.targetDoc;
+            if (from && from.mediaStopTriggerList && this.layoutDoc.presStatus !== PresStatus.Edit) {
+                const mediaDocList = DocListCast(from.mediaStopTriggerList);
+                mediaDocList.forEach((doc) => {
+                    this.stopTempMedia(Cast(doc.presentationTargetDoc, Doc, null));
+                });
+            }
             if (from && from.mediaStop === "auto" && this.layoutDoc.presStatus !== PresStatus.Edit) {
                 this.stopTempMedia(Cast(from.presentationTargetDoc, Doc, null));
             }
@@ -620,14 +626,6 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
         if (viewType === CollectionViewType.Stacking) this.layoutDoc._gridGap = 0;
     });
 
-
-    @action
-    updateMediaStopTriggerList = (list: any, activeItem: Doc): List<Doc> => {
-        const x: List<Doc> = list;
-        x.push(activeItem);
-        return x;
-    }
-
     /**
      * Called when the user changes the view type
      * Either 'List' (stacking) or 'Slides' (carousel)
@@ -639,8 +637,14 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
         const stopDoc = e.target.selectedOptions[0].value as string;
         const stopDocIndex: number = Number(stopDoc[0]);
         activeItem.mediaStopDoc = stopDocIndex;
-        const newList = this.updateMediaStopTriggerList(this.childDocs[stopDocIndex].mediaStopTriggerList, activeItem)
-        this.childDocs[stopDocIndex].mediaStopTriggerList = newList;
+        if (this.childDocs[stopDocIndex - 1].mediaStopTriggerList) {
+            const list = DocListCast(this.childDocs[stopDocIndex - 1].mediaStopTriggerList);
+            list.push(activeItem);
+        } else {
+            this.childDocs[stopDocIndex - 1].mediaStopTriggerList = new List<Doc>();
+            const list = DocListCast(this.childDocs[stopDocIndex - 1].mediaStopTriggerList);
+            list.push(activeItem);
+        }
     });
 
 
-- 
cgit v1.2.3-70-g09d2

