From 9c4701f8a8214544a0e1e6b31887d393e8ad344f Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 5 Oct 2020 16:00:34 -0400
Subject: fixed search over DB to not use quotes when setting field column
 filters.

---
 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 b381bbfa9..1104d8d2a 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -146,7 +146,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                 const mod = "_t:";
                 const newWords: string[] = [];
                 const oldWords = values[0].split(" ");
-                oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + "\"" + word + "\"") : newWords.push("AND " + key + mod + "\"" + word + "\""));
+                oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + word) : newWords.push("AND " + key + mod + word));
                 query = `(${query}) AND (${newWords.join(" ")})`;
             }
             else {
@@ -154,7 +154,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                     const mod = "_t:";
                     const newWords: string[] = [];
                     const oldWords = values[i].split(" ");
-                    oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + "\"" + word + "\"") : newWords.push("AND " + key + mod + "\"" + word + "\""));
+                    oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + word) : newWords.push("AND " + key + mod + word));
                     const v = "(" + newWords.join(" ") + ")";
                     if (i === 0) {
                         query = `(${query}) AND (${v}` + (values.length === 1 ? ")" : "");
-- 
cgit v1.2.3-70-g09d2


From 24e31df47a0d38de8073da69cc4ea78a2e5be6cd Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 8 Oct 2020 20:08:42 -0400
Subject: added hack to save startup state. fixed runtime failure by restoring
 imports in main.tsx

---
 src/client/views/Main.tsx             | 10 ++++++----
 src/client/views/search/SearchBox.tsx |  3 ++-
 src/mobile/MobileMain.tsx             |  2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

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

diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index a5352c94a..3889e2d28 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -1,10 +1,12 @@
-import * as React from 'react';
-import * as ReactDOM from 'react-dom';
-import { AssignAllExtensions } from "../../extensions/General/Extensions";
+import { MainView } from "./MainView";
 import { Docs } from "../documents/Documents";
 import { CurrentUserUtils } from "../util/CurrentUserUtils";
+import * as ReactDOM from 'react-dom';
+import * as React from 'react';
+import { DocServer } from "../DocServer";
+import { AssignAllExtensions } from "../../extensions/General/Extensions";
+import { Networking } from "../Network";
 import { CollectionView } from "./collections/CollectionView";
-import { MainView } from "./MainView";
 
 AssignAllExtensions();
 
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 1104d8d2a..019c703e0 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -24,6 +24,7 @@ import { ViewBoxBaseComponent } from "../DocComponent";
 import { FieldView, FieldViewProps } from '../nodes/FieldView';
 import "./SearchBox.scss";
 import { undoBatch } from "../../util/UndoManager";
+import { DocServer } from "../../DocServer";
 
 export const searchSchema = createSchema({ Document: Doc });
 
@@ -503,7 +504,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                                 Logoff
                         </div>
                         </div>
-                        <div className="searchBox-lozenge">
+                        <div className="searchBox-lozenge" onClick={() => DocServer.PRINT_CACHE()}>
                             {`UI project`}
                         </div>
                         <div className="searchBox-lozenge-dashboard"  >
diff --git a/src/mobile/MobileMain.tsx b/src/mobile/MobileMain.tsx
index 3d4680d58..4a1e26078 100644
--- a/src/mobile/MobileMain.tsx
+++ b/src/mobile/MobileMain.tsx
@@ -14,7 +14,7 @@ AssignAllExtensions();
     await Docs.Prototypes.initialize();
     if (info.id !== "__guest__") {
         // a guest will not have an id registered
-        await CurrentUserUtils.loadUserDocument(info);
+        await CurrentUserUtils.loadUserDocument(info.id);
     }
     document.getElementById('root')!.addEventListener('wheel', event => {
         if (event.ctrlKey) {
-- 
cgit v1.2.3-70-g09d2


From 858fdbf31c9ddbf00eae692cd43e70455a19e1b5 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Sat, 10 Oct 2020 20:49:26 -0400
Subject: fixed docFilters to use up one string field, not 3.  makes
 adding/removing to lists incrementally work with new server code.

---
 src/client/documents/Documents.ts                    | 14 ++++++++++----
 src/client/util/LinkManager.ts                       |  2 +-
 .../views/collections/CollectionSchemaHeaders.tsx    | 14 ++++++++------
 src/client/views/nodes/FilterBox.tsx                 | 16 ++++++++--------
 src/client/views/search/SearchBox.tsx                | 20 +++++++++++---------
 src/fields/Doc.ts                                    | 13 ++++++-------
 src/server/websocket.ts                              |  4 ++--
 7 files changed, 46 insertions(+), 37 deletions(-)

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

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 7d78bd76a..159771145 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -895,8 +895,11 @@ export namespace Docs {
 export namespace DocUtils {
     export function Excluded(d: Doc, docFilters: string[]) {
         const filterFacets: { [key: string]: { [value: string]: string } } = {};  // maps each filter key to an object with value=>modifier fields
-        for (let i = 0; i < docFilters.length; i += 3) {
-            const [key, value, modifiers] = docFilters.slice(i, i + 3);
+        for (let i = 0; i < docFilters.length; i++) {
+            const fields = docFilters[i].split(":");
+            const key = fields[0];
+            const value = fields[1];
+            const modifiers = fields[2];
             if (!filterFacets[key]) {
                 filterFacets[key] = {};
             }
@@ -918,8 +921,11 @@ export namespace DocUtils {
         const childDocs = viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs;
 
         const filterFacets: { [key: string]: { [value: string]: string } } = {};  // maps each filter key to an object with value=>modifier fields
-        for (let i = 0; i < docFilters.length; i += 3) {
-            const [key, value, modifiers] = docFilters.slice(i, i + 3);
+        for (let i = 0; i < docFilters.length; i++) {
+            const fields = docFilters[i].split(":");
+            const key = fields[0];
+            const value = fields[1];
+            const modifiers = fields[2];
             if (!filterFacets[key]) {
                 filterFacets[key] = {};
             }
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index e74ce87f8..1ba6cff6d 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -36,7 +36,7 @@ export class LinkManager {
     public getAllLinks(): Doc[] {
         const lset = new Set<Doc>(DocListCast(Doc.LinkDBDoc().data));
         SharingManager.Instance.users.forEach(user => {
-            DocListCast((user.linkDatabase as Doc)?.data).map(doc => {
+            DocListCast(user.linkDatabase?.data).map(doc => {
                 lset.add(doc);
             });
         });
diff --git a/src/client/views/collections/CollectionSchemaHeaders.tsx b/src/client/views/collections/CollectionSchemaHeaders.tsx
index dbf7488ec..b408fd680 100644
--- a/src/client/views/collections/CollectionSchemaHeaders.tsx
+++ b/src/client/views/collections/CollectionSchemaHeaders.tsx
@@ -261,7 +261,7 @@ export class KeysDropdown extends React.Component<KeysDropdownProps> {
     componentDidMount() {
         document.addEventListener("pointerdown", this.detectClick);
         const filters = Cast(this.props.Document._docFilters, listSpec("string"));
-        if (filters?.includes(this._key)) {
+        if (filters?.some(filter => filter.split(":")[0] === this._key)) {
             runInAction(() => this.closeResultsVisibility = "contents");
         }
     }
@@ -396,19 +396,21 @@ export class KeysDropdown extends React.Component<KeysDropdownProps> {
         });
 
         const filters = Cast(this.props.Document._docFilters, listSpec("string"));
-        if (filters === undefined || filters.length === 0 || filters.includes(this._key) === false) {
+        if (filters === undefined || filters.length === 0 || filters.some(filter => filter.split(":")[0] === this._key) === false) {
             this.props.col.setColor("rgb(241, 239, 235)");
             this.closeResultsVisibility = "none";
         }
-        for (let i = 0; i < (filters?.length ?? 0) - 1; i += 3) {
-            if (filters![i] === this.props.col.heading && keyOptions.includes(filters![i + 1]) === false) {
+        for (let i = 0; i < (filters?.length ?? 0) - 1; i++) {
+            if (filters![i] === this.props.col.heading && keyOptions.includes(filters![i].split(":")[1]) === false) {
                 keyOptions.push(filters![i + 1]);
             }
         }
         const options = keyOptions.map(key => {
             let bool = false;
             if (filters !== undefined) {
-                bool = filters.includes(key) && filters[filters.indexOf(key) + 1] === "check";
+                const ind = filters.findIndex(filter => filter.split(":")[0] === key);
+                const fields = ind === -1 ? undefined : filters[ind].split(":");
+                bool = fields ? fields[1] === "check" : false;
             }
             return <div key={key} className="key-option" style={{
                 border: "1px solid lightgray", paddingLeft: 5, textAlign: "left",
@@ -453,7 +455,7 @@ export class KeysDropdown extends React.Component<KeysDropdownProps> {
 
     updateFilter() {
         const filters = Cast(this.props.Document._docFilters, listSpec("string"));
-        if (filters === undefined || filters.length === 0 || filters.includes(this._key) === false) {
+        if (filters === undefined || filters.length === 0 || filters.some(filter => filter.split(":")[0] === this._key) === false) {
             this.props.col.setColor("rgb(241, 239, 235)");
             this.closeResultsVisibility = "none";
         }
diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx
index d3c0bfba3..0d02a4388 100644
--- a/src/client/views/nodes/FilterBox.tsx
+++ b/src/client/views/nodes/FilterBox.tsx
@@ -94,15 +94,15 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
             const docFilter = Cast(targetDoc._docFilters, listSpec("string"));
             if (docFilter) {
                 let index: number;
-                while ((index = docFilter.findIndex(item => item === facetHeader)) !== -1) {
-                    docFilter.splice(index, 3);
+                while ((index = docFilter.findIndex(item => item.split(":")[0] === facetHeader)) !== -1) {
+                    docFilter.splice(index, 1);
                 }
             }
             const docRangeFilters = Cast(targetDoc._docRangeFilters, listSpec("string"));
             if (docRangeFilters) {
                 let index: number;
-                while ((index = docRangeFilters.findIndex(item => item === facetHeader)) !== -1) {
-                    docRangeFilters.splice(index, 3);
+                while ((index = docRangeFilters.findIndex(item => item.split(":")[0] === facetHeader)) !== -1) {
+                    docRangeFilters.splice(index, 1);
                 }
             }
         } else {
@@ -224,10 +224,10 @@ 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 i = 0; i < docFilters.length; i += 3) {
-        const [header, value, state] = docFilters.slice(i, i + 3);
-        if (header === facetHeader && value === facetValue) {
-            return state;
+    for (let i = 0; i < docFilters.length; i++) {
+        const fields = docFilters[i].split(":"); // split into key:value:modifiers
+        if (fields[0] === facetHeader && fields[1] === facetValue) {
+            return fields[2];
         }
     }
     return undefined;
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 019c703e0..c559d4eb7 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -122,22 +122,24 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
 
         const filters: string[] = [];
 
-        for (let i = 0; i < initialfilters.length; i = i + 3) {
-            if (initialfilters[i + 2] !== undefined) {
-                filters.push(initialfilters[i]);
-                filters.push(initialfilters[i + 1]);
-                filters.push(initialfilters[i + 2]);
+        for (let i = 0; i < initialfilters.length; i++) {
+            const fields = initialfilters[i].split(":");
+            if (fields[2] !== undefined) {
+                filters.push(fields[0]);
+                filters.push(fields[1]);
+                filters.push(fields[2]);
             }
         }
 
         const finalfilters: { [key: string]: string[] } = {};
 
-        for (let i = 0; i < filters.length; i = i + 3) {
-            if (finalfilters[filters[i]] !== undefined) {
-                finalfilters[filters[i]].push(filters[i + 1]);
+        for (let i = 0; i < filters.length; i = i++) {
+            const fields = filters[i].split(":");
+            if (finalfilters[fields[0]] !== undefined) {
+                finalfilters[fields[0]].push(fields[1]);
             }
             else {
-                finalfilters[filters[i]] = [filters[i + 1]];
+                finalfilters[fields[0]] = [fields[1]];
             }
         }
 
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 0e0a49876..7dd894ec4 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -1053,10 +1053,11 @@ export namespace Doc {
         const container = target ?? CollectionDockingView.Instance.props.Document;
         const docFilters = Cast(container._docFilters, listSpec("string"), []);
         runInAction(() => {
-            for (let i = 0; i < docFilters.length; i += 3) {
-                if (docFilters[i] === key && (docFilters[i + 1] === value || modifiers === "match" || modifiers === "remove")) {
-                    if (docFilters[i + 2] === modifiers && modifiers && docFilters[i + 1] === value) return;
-                    docFilters.splice(i, 3);
+            for (let i = 0; i < docFilters.length; i++) {
+                const fields = docFilters[i].split(":"); // split key:value:modifier
+                if (fields[0] === key && (fields[1] === value || modifiers === "match" || modifiers === "remove")) {
+                    if (fields[2] === modifiers && modifiers && fields[1] === value) return;
+                    docFilters.splice(i, 1);
                     container._docFilters = new List<string>(docFilters);
                     break;
                 }
@@ -1065,9 +1066,7 @@ export namespace Doc {
                 if (!docFilters.length && modifiers === "match" && value === undefined) {
                     container._docFilters = undefined;
                 } else if (modifiers !== "remove") {
-                    docFilters.push(key);
-                    docFilters.push(value);
-                    docFilters.push(modifiers);
+                    docFilters.push(key + ":" + value + ":" + modifiers);
                     container._docFilters = new List<string>(docFilters);
                 }
             }
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index 03795d254..1e02b9e58 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -276,7 +276,7 @@ export namespace WebSocket {
         const updatefield = Array.from(Object.keys(diff.diff.$set))[0];
         const newListItems = diff.diff.$set[updatefield].fields;
         const curList = (curListItems as any)?.fields?.[updatefield.replace("fields.", "")]?.fields || [];
-        diff.diff.$set[updatefield].fields = [...curList, ...newListItems.filter((newItem: any) => !curList.some((curItem: any) => curItem.fieldId ? curItem.fieldId === newItem.fieldId : curItem.heading ? curItem.heading === newItem.heading : false))];
+        diff.diff.$set[updatefield].fields = [...curList, ...newListItems.filter((newItem: any) => !curList.some((curItem: any) => curItem.fieldId ? curItem.fieldId === newItem.fieldId : curItem.heading ? curItem.heading === newItem.heading : curItem === newItem))];
         const sendBack = diff.diff.length !== diff.diff.$set[updatefield].fields.length;
         delete diff.diff.length;
         Database.Instance.update(diff.id, diff.diff,
@@ -295,7 +295,7 @@ export namespace WebSocket {
         const updatefield = Array.from(Object.keys(diff.diff.$set))[0];
         const remListItems = diff.diff.$set[updatefield].fields;
         const curList = (curListItems as any)?.fields?.[updatefield.replace("fields.", "")]?.fields || [];
-        diff.diff.$set[updatefield].fields = curList?.filter((curItem: any) => !remListItems.some((remItem: any) => remItem.fieldId ? remItem.fieldId === curItem.fieldId : remItem.heading ? remItem.heading === curItem.heading : false));
+        diff.diff.$set[updatefield].fields = curList?.filter((curItem: any) => !remListItems.some((remItem: any) => remItem.fieldId ? remItem.fieldId === curItem.fieldId : remItem.heading ? remItem.heading === curItem.heading : remItem === curItem));
         const sendBack = diff.diff.length !== diff.diff.$set[updatefield].fields.length;
         delete diff.diff.length;
         Database.Instance.update(diff.id, diff.diff,
-- 
cgit v1.2.3-70-g09d2

