From 3113bd7dfee404eea113633f97027a2370f8d817 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Mon, 25 Feb 2019 00:48:43 -0500 Subject: Got user workspaces working --- src/client/views/Main.tsx | 178 +++++++++++++++++-------------- src/server/authentication/models/User.ts | 2 +- src/server/index.ts | 15 +++ 3 files changed, 113 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 2a3e2780b..97f68f4f5 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -19,6 +19,7 @@ import { Utils } from '../../Utils'; import { ServerUtils } from '../../server/ServerUtil'; import { MessageStore, DocumentTransfer } from '../../server/Message'; import { Database } from '../../server/database'; +import * as request from 'request' configure({ @@ -42,6 +43,21 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { } }), true) +let mainDocId: string; +request.get(window.location.origin + "/getUserDocId", (error, response, body) => { + if (body) { + mainDocId = body; + } else { + mainDocId = Utils.GenerateGuid(); + request.post(window.location.origin + "/setUserDocId", { + body: { + userDocumentId: mainDocId + }, + json: true + }) + } + init(); +}) //runInAction(() => // let doc1 = Documents.TextDocument({ title: "hello" }); @@ -59,91 +75,91 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { // schemaDocs[4].SetData(KS.Author, "Bob", TextField); // schemaDocs.push(doc2); // const doc7 = Documents.SchemaDocument(schemaDocs) +function init() { + Documents.initProtos(() => { + Utils.EmitCallback(Server.Socket, MessageStore.GetField, mainDocId, (res: any) => { + console.log("HELLO WORLD") + console.log("RESPONSE: " + res) + let mainContainer: Document; + if (res) { + var lid = KeyStore.Layout.Id; + let obj = ServerUtils.FromJson(res) as Document + mainContainer = obj + } + else { + const docset: Document[] = []; + mainContainer = Documents.CollectionDocument(docset, { x: 0, y: 400, title: "mini collection" }, mainDocId); + let args = new DocumentTransfer(mainContainer.ToJson()) + Utils.Emit(Server.Socket, MessageStore.AddDocument, args) + } -const mainDocId = "mainDoc"; -Documents.initProtos(() => { - Utils.EmitCallback(Server.Socket, MessageStore.GetField, mainDocId, (res: any) => { - console.log("HELLO WORLD") - console.log("RESPONSE: " + res) - let mainContainer: Document; - if (res) { - var lid = KeyStore.Layout.Id; - let obj = ServerUtils.FromJson(res) as Document - mainContainer = obj - } - else { - const docset: Document[] = []; - mainContainer = Documents.CollectionDocument(docset, { x: 0, y: 400, title: "mini collection" }, mainDocId); - let args = new DocumentTransfer(mainContainer.ToJson()) - Utils.Emit(Server.Socket, MessageStore.AddDocument, args) - } + let addImageNode = action(() => { + mainContainer.GetList(KeyStore.Data, []).push(Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { + x: 0, y: 300, width: 200, height: 200, title: "added note" + })); + }) + let addTextNode = action(() => { + mainContainer.GetList(KeyStore.Data, []).push(Documents.TextDocument({ + x: 0, y: 300, width: 200, height: 200, title: "added note" + })); + }) + let addColNode = action(() => { + mainContainer.GetList(KeyStore.Data, []).push(Documents.CollectionDocument([], { + x: 0, y: 300, width: 200, height: 200, title: "added note" + })); + }) - let addImageNode = action(() => { - mainContainer.GetList(KeyStore.Data, []).push(Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { - x: 0, y: 300, width: 200, height: 200, title: "added note" - })); - }) - let addTextNode = action(() => { - mainContainer.GetList(KeyStore.Data, []).push(Documents.TextDocument({ - x: 0, y: 300, width: 200, height: 200, title: "added note" - })); - }) - let addColNode = action(() => { - mainContainer.GetList(KeyStore.Data, []).push(Documents.CollectionDocument([], { - x: 0, y: 300, width: 200, height: 200, title: "added note" - })); - }) + let clearDatabase = action(() => { + Utils.Emit(Server.Socket, MessageStore.DeleteAll, {}); + }) - let clearDatabase = action(() => { - Utils.Emit(Server.Socket, MessageStore.DeleteAll, {}); + ReactDOM.render(( +
+ + + + + + + + + + +
), + document.getElementById('root')); }) - - ReactDOM.render(( -
- - - - - - - - - - -
), - document.getElementById('root')); - }) -}); + }); +} // let doc5 = Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { // x: 650, y: 500, width: 600, height: 600, title: "cat 2" // }); diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts index ed2952e48..bc838bb47 100644 --- a/src/server/authentication/models/User.ts +++ b/src/server/authentication/models/User.ts @@ -47,7 +47,7 @@ const userSchema = new mongoose.Schema({ passwordResetToken: String, passwordResetExpires: Date, - workspaces: Array, + userDocumentId: String, facebook: String, twitter: String, diff --git a/src/server/index.ts b/src/server/index.ts index 7189b32a0..87b6b0005 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -89,6 +89,21 @@ app.get("/home", (req, res) => { res.sendFile(path.join(__dirname, '../../deploy/index.html')); }); +app.get("/getUserDocId", (req, res) => { + console.log(req.user) + if (!req.user) { + return; + } + res.send(req.user.userDocumentId || ""); +}) + +app.post("/setUserDocId", (req, res) => { + if (!req.user) { + return; + } + req.user.update({ $set: { userDocumentId: req.body.userDocumentId } }, () => { }); +}) + // anyone attempting to navigate to localhost at this port will // first have to login app.get("/", getEntry); -- cgit v1.2.3-70-g09d2