From f1ee3a6baffb22093d81e123d70f6ec9631c2075 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 15 Oct 2020 15:20:51 -0400
Subject: got rid of isDragging in favor of a field on the PresElement.  fixed
 moving items in presBox by fixing websocket to maintain ordering on
 sequential operations on a list.  fixed list splicing to not call addToSet
 unless splicing is at end of list.  fixed setting return scale when following
 link into portal

---
 .../views/presentationview/PresElementBox.tsx      | 43 +++++++++++-----------
 1 file changed, 22 insertions(+), 21 deletions(-)

(limited to 'src/client/views/presentationview/PresElementBox.tsx')

diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx
index 9052967e5..1d6721bca 100644
--- a/src/client/views/presentationview/PresElementBox.tsx
+++ b/src/client/views/presentationview/PresElementBox.tsx
@@ -1,5 +1,5 @@
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, computed, IReactionDisposer, reaction, runInAction } from "mobx";
+import { action, computed, IReactionDisposer, reaction, runInAction, observable } from "mobx";
 import { observer } from "mobx-react";
 import { Doc, DataSym, DocListCast } from "../../../fields/Doc";
 import { documentSchema } from '../../../fields/documentSchemas';
@@ -8,13 +8,11 @@ import { createSchema, makeInterface, listSpec } from '../../../fields/Schema';
 import { Cast, NumCast, BoolCast, ScriptCast, StrCast } from "../../../fields/Types";
 import { emptyFunction, emptyPath, returnFalse, returnTrue, returnOne, returnZero, numberRange, setupMoveUpEvents } from "../../../Utils";
 import { Transform } from "../../util/Transform";
-import { CollectionViewType } from '../collections/CollectionView';
 import { ViewBoxBaseComponent } from '../DocComponent';
 import { ContentFittingDocumentView } from '../nodes/ContentFittingDocumentView';
 import { FieldView, FieldViewProps } from '../nodes/FieldView';
 import "./PresElementBox.scss";
 import React = require("react");
-import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocumentView";
 import { PresBox, PresMovement } from "../nodes/PresBox";
 import { DocumentType } from "../../documents/DocumentTypes";
 import { Tooltip } from "@material-ui/core";
@@ -45,6 +43,8 @@ const PresDocument = makeInterface(presSchema, documentSchema);
 export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDocument>(PresDocument) {
     public static LayoutString(fieldKey: string) { return FieldView.LayoutString(PresElementBox, fieldKey); }
     _heightDisposer: IReactionDisposer | undefined;
+
+    @observable _dragging = false;
     // these fields are conditionally computed fields on the layout document that take this document as a parameter
     @computed get indexInPres() { return Number(this.lookupField("indexInPres")); }  // the index field is where this document is in the presBox display list (since this value is different for each presentation element, the value can't be stored on the layout template which is used by all display elements)
     @computed get collapsedHeight() { return Number(this.lookupField("presCollapsedHeight")); } // the collapsed height changes depending on the state of the presBox.  We could store this on the presentation element template if it's used by only one presentation - but if it's shared by multiple, then this value must be looked up
@@ -159,9 +159,9 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
         e.preventDefault();
     }
 
+    @action
     stopDrag = (e: PointerEvent) => {
-        const activeItem = this.rootDoc;
-        activeItem.dragging = false;
+        this._dragging = false;
         e.stopPropagation();
         e.preventDefault();
     }
@@ -172,12 +172,12 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
         const dragItem: HTMLElement[] = [];
         PresBox.Instance._dragArray.map(ele => {
             const doc = ele;
-            doc.className = "presItem-slide"
+            doc.className = "presItem-slide";
             dragItem.push(doc);
         });
         if (activeItem) {
             DragManager.StartDocumentDrag(dragItem.map(ele => ele), dragData, e.clientX, e.clientY);
-            activeItem.dragging = true;
+            runInAction(() => this._dragging = true);
             return true;
         }
         return false;
@@ -189,18 +189,20 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
     }
 
     onPointerMove = (e: PointerEvent) => {
-        const slide = this._itemRef.current!;
-        const rect = slide?.getBoundingClientRect();
-        let y = e.clientY - rect.top;  //y position within the element.
-        let height = slide.clientHeight;
-        let halfLine = height / 2;
-        if (DragManager.docsBeingDragged.length > 1) {
-            if (y <= halfLine) {
-                slide.style.borderTop = "solid 2px #5B9FDD";
-                slide.style.borderBottom = "0px";
-            } else if (y > halfLine) {
-                slide.style.borderTop = "0px";
-                slide.style.borderBottom = "solid 2px #5B9FDD";
+        const slide = this._itemRef.current;
+        if (slide) {
+            const rect = slide.getBoundingClientRect();
+            const y = e.clientY - rect.top;  //y position within the element.
+            const height = slide.clientHeight;
+            const halfLine = height / 2;
+            if (DragManager.docsBeingDragged.length) {
+                if (y <= halfLine) {
+                    slide.style.borderTop = "solid 2px #5B9FDD";
+                    slide.style.borderBottom = "0px";
+                } else if (y > halfLine) {
+                    slide.style.borderTop = "0px";
+                    slide.style.borderBottom = "solid 2px #5B9FDD";
+                }
             }
         }
         document.removeEventListener("pointermove", this.onPointerMove);
@@ -244,7 +246,6 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
 
     @computed get mainItem() {
         const isSelected: boolean = PresBox.Instance._selectedArray.includes(this.rootDoc);
-        const isDragging: boolean = BoolCast(this.rootDoc.dragging);
         const toolbarWidth: number = PresBox.Instance.toolbarWidth;
         const showMore: boolean = PresBox.Instance.toolbarWidth >= 300;
         const targetDoc: Doc = Cast(this.rootDoc.presentationTargetDoc, Doc, null);
@@ -252,7 +253,7 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
         return (
             <div className={`presItem-container`} key={this.props.Document[Id] + this.indexInPres}
                 ref={this._itemRef}
-                style={{ backgroundColor: isSelected ? "#AEDDF8" : "rgba(0,0,0,0)", opacity: isDragging ? 0.3 : 1 }}
+                style={{ backgroundColor: isSelected ? "#AEDDF8" : "rgba(0,0,0,0)", opacity: this._dragging ? 0.3 : 1 }}
                 onClick={e => {
                     e.stopPropagation();
                     e.preventDefault();
-- 
cgit v1.2.3-70-g09d2


From 67e3a220a622ff1a1a54f04df48d57c34a3a387d Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 16 Oct 2020 01:26:01 -0400
Subject: fixed compile warn ings.

---
 src/client/util/SharingManager.tsx                   | 2 +-
 src/client/views/nodes/FilterBox.tsx                 | 2 +-
 src/client/views/presentationview/PresElementBox.tsx | 6 +++---
 src/client/views/search/SearchBox.tsx                | 2 +-
 src/fields/util.ts                                   | 4 ++--
 5 files changed, 8 insertions(+), 8 deletions(-)

(limited to 'src/client/views/presentationview/PresElementBox.tsx')

diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 0cd5332ca..2b13d2a44 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -140,7 +140,7 @@ export class SharingManager extends React.Component<{}> {
             });
             return Promise.all(evaluating).then(() => {
                 runInAction(() => {
-                    for (let sharer of sharingDocs) {
+                    for (const sharer of sharingDocs) {
                         if (!this.users.find(user => user.user.email === sharer.user.email)) {
                             this.users.push(sharer);
                         }
diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx
index bb20f91c0..6f01e5916 100644
--- a/src/client/views/nodes/FilterBox.tsx
+++ b/src/client/views/nodes/FilterBox.tsx
@@ -224,7 +224,7 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
 
 Scripting.addGlobal(function determineCheckedState(layoutDoc: Doc, facetHeader: string, facetValue: string) {
     const docFilters = Cast(layoutDoc._docFilters, listSpec("string"), []);
-    for (let filter of docFilters) {
+    for (const filter of docFilters) {
         const fields = filter.split(":"); // split into key:value:modifiers
         if (fields[0] === facetHeader && fields[1] === facetValue) {
             return fields[2];
diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx
index 56a1cd116..ab4cadab0 100644
--- a/src/client/views/presentationview/PresElementBox.tsx
+++ b/src/client/views/presentationview/PresElementBox.tsx
@@ -192,9 +192,9 @@ export class PresElementBox extends ViewBoxBaseComponent<FieldViewProps, PresDoc
         const slide = this._itemRef.current!;
         if (slide && DragManager.docsBeingDragged.length > 0) {
             const rect = slide.getBoundingClientRect();
-            let y = e.clientY - rect.top;  //y position within the element.
-            let height = slide.clientHeight;
-            let halfLine = height / 2;
+            const y = e.clientY - rect.top;  //y position within the element.
+            const height = slide.clientHeight;
+            const halfLine = height / 2;
             if (y <= halfLine) {
                 slide.style.borderTop = "solid 2px #5B9FDD";
                 slide.style.borderBottom = "0px";
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 13fcccdcf..bc00e93a5 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -122,7 +122,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
 
         const filters: string[] = [];
 
-        for (let initFilter of initialfilters) {
+        for (const initFilter of initialfilters) {
             const fields = initFilter.split(":");
             if (fields[2] !== undefined) {
                 filters.push(fields[0]);
diff --git a/src/fields/util.ts b/src/fields/util.ts
index f27b45057..a374c7f54 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -370,9 +370,9 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
                 diff?.op === "$remFromSet" ? { '$remFromSet': { ["fields." + prop]: SerializationHelper.Serialize(new List<Doc>(diff.items)) } }
                     : { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } };
         !op.$set && ((op as any).length = diff.length);
-        let prevValue = ObjectField.MakeCopy(lastValue as List<any>);
+        const prevValue = ObjectField.MakeCopy(lastValue as List<any>);
         lastValue = ObjectField.MakeCopy(value);
-        let newValue = ObjectField.MakeCopy(value);
+        const newValue = ObjectField.MakeCopy(value);
 
         if (!(value instanceof CursorField) && !(value?.some?.((v: any) => v instanceof CursorField))) {
             !receiver[UpdatingFromServer] && UndoManager.AddEvent(
-- 
cgit v1.2.3-70-g09d2

