From 79b1ae37d4a89130026a33d52139a69fbe444698 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 15 Oct 2020 15:29:45 -0400
Subject: fixed warnings

---
 src/client/views/search/SearchBox.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/client/views/search/SearchBox.tsx')

diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index c559d4eb7..13fcccdcf 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -122,8 +122,8 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
 
         const filters: string[] = [];
 
-        for (let i = 0; i < initialfilters.length; i++) {
-            const fields = initialfilters[i].split(":");
+        for (let initFilter of initialfilters) {
+            const fields = initFilter.split(":");
             if (fields[2] !== undefined) {
                 filters.push(fields[0]);
                 filters.push(fields[1]);
-- 
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/search/SearchBox.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


From 5816840af60f97a34318a52a5276482cab392496 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 16 Oct 2020 15:48:54 -0400
Subject: updated user initialization code to not generate server traffic when
 creating a new account.  set user accounts to update their cache 2.5s after
 login.

---
 src/client/DocServer.ts               |  5 ++---
 src/client/documents/Documents.ts     |  4 +++-
 src/client/util/CurrentUserUtils.ts   | 15 ++++++++++-----
 src/client/views/GlobalKeyHandler.ts  |  2 +-
 src/client/views/Main.tsx             |  3 ++-
 src/client/views/search/SearchBox.tsx |  2 +-
 src/server/websocket.ts               | 11 +++++++----
 7 files changed, 26 insertions(+), 16 deletions(-)

(limited to 'src/client/views/search/SearchBox.tsx')

diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 00f9877c3..1d7497cf8 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -28,13 +28,13 @@ import * as rp from 'request-promise';
 export namespace DocServer {
     let _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
 
-    export function PRINT_CACHE() {
+    export function UPDATE_SERVER_CACHE(print: boolean = false) {
         const strings: string[] = [];
         Array.from(Object.keys(_cache)).forEach(key => {
             const doc = _cache[key];
             if (doc instanceof Doc) strings.push(StrCast(doc.author) + " " + StrCast(doc.title) + " " + StrCast(Doc.GetT(doc, "title", "string", true)));
         });
-        strings.sort().forEach((str, i) => console.log(i.toString() + " " + str));
+        print && strings.sort().forEach((str, i) => console.log(i.toString() + " " + str));
         rp.post(Utils.prepend("/setCacheDocumentIds"), {
             body: {
                 cacheDocumentIds: Array.from(Object.keys(_cache)).join(";"),
@@ -348,7 +348,6 @@ export namespace DocServer {
         }
 
         if (requestedIds.length) {
-
             // 2) synchronously, we emit a single callback to the server requesting the serialized (i.e. represented by a string)
             // fields for the given ids. This returns a promise, which, when resolved, indicates that all the JSON serialized versions of
             // the fields have been returned from the server
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 45c465d84..d7c9af1a3 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -236,6 +236,8 @@ class EmptyBox {
 
 export namespace Docs {
 
+    export let newAccount: boolean = false;
+
     export namespace Prototypes {
 
         type LayoutSource = { LayoutString: (key: string) => string };
@@ -392,7 +394,7 @@ export namespace Docs {
             // non-guid string ids for each document prototype
             const prototypeIds = Object.values(DocumentType).filter(type => type !== DocumentType.NONE).map(type => type + suffix);
             // fetch the actual prototype documents from the server
-            const actualProtos = await DocServer.GetRefFields(prototypeIds);
+            const actualProtos = Docs.newAccount ? {} : await DocServer.GetRefFields(prototypeIds);
 
             // update this object to include any default values: DocumentOptions for all prototypes
             prototypeIds.map(id => {
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index dcbeba8cd..f43b6df44 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -878,7 +878,7 @@ export class CurrentUserUtils {
     // Sharing sidebar is where shared documents are contained
     static async setupSharingSidebar(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
         if (doc.myLinkDatabase === undefined) {
-            let linkDocs = await DocServer.GetRefField(linkDatabaseId);
+            let linkDocs = Docs.newAccount ? undefined : await DocServer.GetRefField(linkDatabaseId);
             if (!linkDocs) {
                 linkDocs = new Doc(linkDatabaseId, true);
                 (linkDocs as Doc).author = Doc.CurrentUserEmail;
@@ -888,7 +888,7 @@ export class CurrentUserUtils {
             doc.myLinkDatabase = new PrefetchProxy(linkDocs);
         }
         if (doc.mySharedDocs === undefined) {
-            let sharedDocs = await DocServer.GetRefField(sharingDocumentId + "outer");
+            let sharedDocs = Docs.newAccount ? undefined : await DocServer.GetRefField(sharingDocumentId + "outer");
             if (!sharedDocs) {
                 sharedDocs = Docs.Create.StackingDocument([], {
                     title: "My SharedDocs", childDropAction: "alias", system: true, contentPointerEvents: "none", childLimitHeight: 0, _yMargin: 50, _gridGap: 15,
@@ -1024,6 +1024,7 @@ export class CurrentUserUtils {
         //         Doc.AddDocToList(Cast(doc["template-notes"], Doc, null), "data", deleg);
         //     }
         // });
+        setTimeout(() => DocServer.UPDATE_SERVER_CACHE(), 2500);
         return doc;
     }
 
@@ -1047,8 +1048,12 @@ export class CurrentUserUtils {
         await rp.get(Utils.prepend("/getUserDocumentIds")).then(ids => {
             const { userDocumentId, sharingDocumentId, linkDatabaseId } = JSON.parse(ids);
             if (userDocumentId !== "guest") {
-                return DocServer.GetRefField(userDocumentId).then(async field =>
-                    this.updateUserDocument(Doc.SetUserDoc(field instanceof Doc ? field : new Doc(userDocumentId, true)), sharingDocumentId, linkDatabaseId));
+                return DocServer.GetRefField(userDocumentId).then(async field => {
+                    Docs.newAccount = !(field instanceof Doc);
+                    await Docs.Prototypes.initialize();
+                    const userDoc = Docs.newAccount ? new Doc(userDocumentId, true) : field as Doc;
+                    return this.updateUserDocument(Doc.SetUserDoc(userDoc), sharingDocumentId, linkDatabaseId);
+                });
             } else {
                 throw new Error("There should be a user id! Why does Dash think there isn't one?");
             }
@@ -1108,7 +1113,7 @@ export class CurrentUserUtils {
                 const response = await fetch(upload, { method: "POST", body: formData });
                 const json = await response.json();
                 if (json !== "error") {
-                    const doc = await DocServer.GetRefField(json);
+                    const doc = Docs.newAccount ? undefined : await DocServer.GetRefField(json);
                     if (doc instanceof Doc) {
                         setTimeout(() => SearchUtil.Search(`{!join from=id to=proto_i}id:link*`, true, {}).then(docs =>
                             docs.docs.forEach(d => LinkManager.Instance.addLink(d))), 2000); // need to give solr some time to update so that this query will find any link docs we've added.
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 89292a445..fb360ee26 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -56,7 +56,7 @@ export class KeyManager {
 
     public handle = action(async (e: KeyboardEvent) => {
         if (e.key?.toLowerCase() === "shift" && e.ctrlKey && e.altKey) KeyManager.Instance.ShiftPressed = true;
-        if (!Doc.UserDoc().noviceMode && e.key.toLocaleLowerCase() === "shift") DocServer.PRINT_CACHE();
+        if (!Doc.UserDoc().noviceMode && e.key.toLocaleLowerCase() === "shift") DocServer.UPDATE_SERVER_CACHE(true);
         const keyname = e.key && e.key.toLowerCase();
         this.handleGreedy(keyname);
 
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 3889e2d28..c256d2ebb 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -13,10 +13,11 @@ AssignAllExtensions();
 (async () => {
     window.location.search.includes("safe") && CollectionView.SetSafeMode(true);
     const info = await CurrentUserUtils.loadCurrentUser();
-    await Docs.Prototypes.initialize();
     if (info.id !== "__guest__") {
         // a guest will not have an id registered
         await CurrentUserUtils.loadUserDocument(info.id);
+    } else {
+        await Docs.Prototypes.initialize();
     }
     document.getElementById('root')!.addEventListener('wheel', event => {
         if (event.ctrlKey) {
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index bc00e93a5..3872cbb18 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -506,7 +506,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                                 Logoff
                         </div>
                         </div>
-                        <div className="searchBox-lozenge" onClick={() => DocServer.PRINT_CACHE()}>
+                        <div className="searchBox-lozenge" onClick={() => DocServer.UPDATE_SERVER_CACHE()}>
                             {`UI project`}
                         </div>
                         <div className="searchBox-lozenge-dashboard"  >
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index e5692a7dd..490760441 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -207,9 +207,12 @@ export namespace WebSocket {
         }
     }
 
+    function GetRefFieldLocal([id, callback]: [string, (result?: Transferable) => void]) {
+        return Database.Instance.getDocument(id, callback);
+    }
     function GetRefField([id, callback]: [string, (result?: Transferable) => void]) {
         process.stdout.write(`.`);
-        Database.Instance.getDocument(id, callback);
+        GetRefFieldLocal([id, callback]);
     }
 
     function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => void]) {
@@ -311,9 +314,9 @@ export namespace WebSocket {
 
 
     function UpdateField(socket: Socket, diff: Diff) {
-        if (diff.diff.$addToSet) return GetRefField([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own
-        if (diff.diff.$remFromSet) return GetRefField([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own
-        return GetRefField([diff.id, (result?: Transferable) => SetField(socket, diff, result)]);
+        if (diff.diff.$addToSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own
+        if (diff.diff.$remFromSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own
+        return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]);
     }
     function SetField(socket: Socket, diff: Diff, curListItems?: Transferable) {
         Database.Instance.update(diff.id, diff.diff,
-- 
cgit v1.2.3-70-g09d2

