From 2f3adfaf5dfc3acfa3f1f54c9334aebd3a91575a Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Tue, 7 Jun 2022 14:23:11 -0400
Subject: fixed bugs just introduced for presbox - numbering, minibox
 selection.

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

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

diff --git a/src/client/views/nodes/trails/PresBox.tsx b/src/client/views/nodes/trails/PresBox.tsx
index 980bdf4d6..1a4be8e0c 100644
--- a/src/client/views/nodes/trails/PresBox.tsx
+++ b/src/client/views/nodes/trails/PresBox.tsx
@@ -104,7 +104,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() {
     @observable private presentTools: boolean = false;
     @computed get isTreeOrStack() {return [CollectionViewType.Tree, CollectionViewType.Stacking].includes(StrCast(this.layoutDoc._viewType) as any) }
     @computed get isTree() { return this.layoutDoc._viewType === CollectionViewType.Tree;}
-    @computed get presFieldKey() { return StrCast(this.dataDoc.presFieldKey); }
+    @computed get presFieldKey() { return StrCast(this.layoutDoc.presFieldKey, "data"); }
     @computed get childDocs() { return DocListCast(this.rootDoc[this.presFieldKey]); }
     @observable _treeViewMap: Map<Doc, number> = new Map();
 
@@ -625,15 +625,15 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() {
      * Called when the user changes the view type
      * Either 'List' (stacking) or 'Slides' (carousel)
      */
-    // @undoBatch
+    @undoBatch
     viewChanged = action((e: React.ChangeEvent) => {
         //@ts-ignore
         const viewType = e.target.selectedOptions[0].value as CollectionViewType;
+        this.layoutDoc.presFieldKey = this.fieldKey+(viewType === CollectionViewType.Tree ?"-linearized":"");
         // pivot field may be set by the user in timeline view (or some other way) -- need to reset it here
         [CollectionViewType.Tree || CollectionViewType.Stacking].includes(viewType) && (this.rootDoc._pivotField = undefined);
         this.rootDoc._viewType = viewType;
         if (this.isTreeOrStack) {
-            this.layoutDoc.presFieldKey = this.fieldKey+(this.isTree ?"-linearized":"");
             this.layoutDoc._gridGap = 0;
         }
     });
@@ -2463,7 +2463,11 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() {
         }
         if (this._treeViewMap.get(treeViewDoc) !== indexNum) {
             this._treeViewMap.set(treeViewDoc, indexNum);
-            this.dataDoc[this.presFieldKey] = new List<Doc>(this.sort(this._treeViewMap)); // this is a flat array of Docs
+            const sorted = this.sort(this._treeViewMap);
+            const curList = DocListCast(this.dataDoc[this.presFieldKey]);
+            if (sorted.length !== curList.length || sorted.some((doc,ind) => doc !== curList[ind])) {
+                this.dataDoc[this.presFieldKey] = new List<Doc>(sorted); // this is a flat array of Docs
+            }
         }
         return this.childDocs;
     }
@@ -2489,7 +2493,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() {
         const presEnd: boolean = !this.layoutDoc.presLoop && (this.itemIndex === this.childDocs.length - 1);
         const presStart: boolean = !this.layoutDoc.presLoop && (this.itemIndex === 0);
         return CurrentUserUtils.OverlayDocs.includes(this.rootDoc) ?
-            <div className="miniPres">
+            <div className="miniPres" onClick={e => e.stopPropagation()}>
                 <div className="presPanelOverlay" style={{ display: "inline-flex", height: 30, background: '#323232', top: 0, zIndex: 3000000, boxShadow: presKeyEvents ? '0 0 0px 3px ' + Colors.MEDIUM_BLUE : undefined }}>
                     <Tooltip title={<><div className="dash-tooltip">{"Loop"}</div></>}><div className="presPanel-button" style={{ color: this.layoutDoc.presLoop ? Colors.MEDIUM_BLUE : undefined }}
                         onPointerDown={e => setupMoveUpEvents(this, e, returnFalse, returnFalse, () => this.layoutDoc.presLoop = !this.layoutDoc.presLoop, false, false)}><FontAwesomeIcon icon={"redo-alt"} /></div></Tooltip>
-- 
cgit v1.2.3-70-g09d2

