From 4c8eee9811abd072d2a6adfe24eaf04f980ccf21 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Wed, 9 Aug 2023 15:21:20 -0400
Subject: updated file system to include recentlyClosed, Shared, and Dashboards
 and fixed drag drop to make sense for the filesystem.   Fixed loading
 documents to happen in one batch by fixing UPDATE_CACHED_DOCS to save only
 documents accessible from current dashboard.

---
 src/client/views/Main.tsx | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

(limited to 'src/client/views/Main.tsx')

diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 2fa42d091..2a73d77ed 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -6,10 +6,7 @@ import * as React from 'react';
 import * as ReactDOM from 'react-dom/client';
 import { AssignAllExtensions } from '../../extensions/General/Extensions';
 import { FieldLoader } from '../../fields/FieldLoader';
-import { DocServer } from '../DocServer';
-import { Docs } from '../documents/Documents';
 import { CurrentUserUtils } from '../util/CurrentUserUtils';
-import { LinkManager } from '../util/LinkManager'; // this must come before importing Docs and CurrentUserUtils
 import { ReplayMovements } from '../util/ReplayMovements';
 import { TrackMovements } from '../util/TrackMovements';
 import { CollectionView } from './collections/CollectionView';
@@ -20,7 +17,7 @@ import './global/globalScripts';
 dotenv.config();
 
 AssignAllExtensions();
-FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0 }; // bcz: not sure why this is needed to get the code loaded properly...
+FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' }; // bcz: not sure why this is needed to get the code loaded properly...
 
 (async () => {
     MainView.Live = window.location.search.includes('live');
-- 
cgit v1.2.3-70-g09d2


From d48eb2da82ff88d52d42f6f5c4c553fa614e7f02 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 10 Aug 2023 09:25:48 -0400
Subject: merged /getUserDocumentIds into /getCurrentUser to avoid extra server
 round trip

---
 src/client/util/CurrentUserUtils.ts   | 39 ++++++++++++++++-------------------
 src/client/views/Main.tsx             |  6 +++++-
 src/server/ApiManagers/UserManager.ts |  3 ++-
 3 files changed, 25 insertions(+), 23 deletions(-)

(limited to 'src/client/views/Main.tsx')

diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 017fb6061..f8fc2b531 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -917,7 +917,7 @@ export class CurrentUserUtils {
     public static async loadCurrentUser() {
         return rp.get(Utils.prepend("/getCurrentUser")).then(async response => {
             if (response) {
-                const result: { id: string, email: string, cacheDocumentIds: string, resolvedPorts: string } = JSON.parse(response);
+                const result: { userDocumentId: string, sharingDocumentId: string, linkDatabaseId: string,  email: string, cacheDocumentIds: string, resolvedPorts: string } = JSON.parse(response);
                 Doc.CurrentUserEmail = result.email;
                 resolvedPorts = result.resolvedPorts as any;
                 DocServer.init(window.location.protocol, window.location.hostname, resolvedPorts.socket, result.email);
@@ -936,27 +936,24 @@ export class CurrentUserUtils {
         });
     }
 
-    public static async loadUserDocument(id: string) {
-        await rp.get(Utils.prepend("/getUserDocumentIds")).then(ids => {
-            const { userDocumentId, sharingDocumentId, linkDatabaseId } = JSON.parse(ids);
-            if (userDocumentId) {
-                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;
-                    this.updateUserDocument(Doc.SetUserDoc(userDoc), sharingDocumentId, linkDatabaseId);
-                    if (Docs.newAccount) {
-                        if (Doc.CurrentUserEmail === "guest") {
-                            DashboardView.createNewDashboard(undefined, "guest dashboard");
-                        } else {
-                            userDoc.activePage = "home";
-                        }
-                    }
-                    return userDoc;
-                });
-            } else {
-                throw new Error("There should be a user id! Why does Dash think there isn't one?");
+    public static async loadUserDocument(info:{
+        userDocumentId: string;
+        sharingDocumentId: string;
+        linkDatabaseId: string;
+    }) {
+        return DocServer.GetRefField(info.userDocumentId).then(async field => {
+            Docs.newAccount = !(field instanceof Doc);
+            await Docs.Prototypes.initialize();
+            const userDoc = Docs.newAccount ? new Doc(info.userDocumentId, true) : field as Doc;
+            this.updateUserDocument(Doc.SetUserDoc(userDoc), info.sharingDocumentId, info.linkDatabaseId);
+            if (Docs.newAccount) {
+                if (Doc.CurrentUserEmail === "guest") {
+                    DashboardView.createNewDashboard(undefined, "guest dashboard");
+                } else {
+                    userDoc.activePage = "home";
+                }
             }
+            return userDoc;
         });
     }
 
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 2a73d77ed..6dd1d53ee 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -26,7 +26,11 @@ FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' };
     window.location.search.includes('safe') && CollectionView.SetSafeMode(true);
     const info = await CurrentUserUtils.loadCurrentUser();
     // if (info.email === 'guest') DocServer.Control.makeReadOnly();
-    await CurrentUserUtils.loadUserDocument(info.id);
+    if (!info.userDocumentId) {
+        alert('Fatal Error: user not found in database');
+        return;
+    }
+    await CurrentUserUtils.loadUserDocument(info);
     setTimeout(() => {
         document.getElementById('root')!.addEventListener(
             'wheel',
diff --git a/src/server/ApiManagers/UserManager.ts b/src/server/ApiManagers/UserManager.ts
index a00a7ca5d..c4555fa8d 100644
--- a/src/server/ApiManagers/UserManager.ts
+++ b/src/server/ApiManagers/UserManager.ts
@@ -68,7 +68,8 @@ export default class UserManager extends ApiManager {
         register({
             method: Method.GET,
             subscription: '/getCurrentUser',
-            secureHandler: ({ res, user: { _id, email, cacheDocumentIds } }) => res.send(JSON.stringify({ id: _id, email, cacheDocumentIds, resolvedPorts })),
+            secureHandler: ({ res, user }) =>
+                res.send(JSON.stringify({ userDocumentId: user.userDocumentId, linkDatabaseId: user.linkDatabaseId, sharingDocumentId: user.sharingDocumentId, email: user.email, cacheDocumentIds: user.cacheDocumentIds, resolvedPorts })),
             publicHandler: ({ res }) => res.send(JSON.stringify({ id: '__guest__', email: 'guest' })),
         });
 
-- 
cgit v1.2.3-70-g09d2

