diff options
author | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-03-09 16:27:24 -0500 |
---|---|---|
committer | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-03-09 16:27:24 -0500 |
commit | e673d4f70b8feb37dcd328440c019a49f8a22e88 (patch) | |
tree | a42a1118591df964871a6d5e4fb4b5fbafe9d3c4 /src | |
parent | 8ea26fc316685f0a3d1b81b7c2e8bd612acbb99c (diff) |
Fixed slight bug with timing of workspace retrieval
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/Main.tsx | 22 | ||||
-rw-r--r-- | src/server/authentication/controllers/WorkspacesMenu.tsx | 4 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index cb13e172e..b160a7671 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -35,11 +35,6 @@ export class Main extends React.Component { this.initEventListeners(); Documents.initProtos(() => { - // retrieve all workspace documents from the server - request.get(this.contextualize("getAllWorkspaceIds"), (error, res, body) => { - let ids = JSON.parse(body) as string[]; - Server.GetFields(ids, action((fields: { [id: string]: Field }) => this.userWorkspaces = ids.map(id => fields[id] as Document))); - }) this.initAuthenticationRouters(); }); } @@ -59,34 +54,39 @@ export class Main extends React.Component { // Load the user's active workspace, or create a new one if initial session after signup request.get(this.contextualize("getActiveWorkspaceId"), (error, response, body) => { if (body) { - console.log("FROM THE TOP, SOMEONE'S ALREADY BEEN HERE"); Server.GetField(body, field => { if (field instanceof Document) { this.openDocument(field); } else { - this.createNewWorkspace(); + this.createNewWorkspace(true); } }); } else { - console.log("FROM THE TOP, WE THINK THERE'S NO CURRENT USER"); - this.createNewWorkspace(); + this.createNewWorkspace(true); } }); } @action - createNewWorkspace = (): void => { + createNewWorkspace = (init: boolean): void => { let mainDoc = Documents.DockDocument(JSON.stringify({ content: [{ type: 'row', content: [] }] }), { title: `Main Container ${this.userWorkspaces.length}` }); let newId = mainDoc.Id; request.post(this.contextualize("addWorkspaceId"), { body: { target: newId }, json: true + }, () => { + if (init) { + // retrieve all workspace documents from the server + request.get(this.contextualize("getAllWorkspaceIds"), (error, res, body) => { + let ids = JSON.parse(body) as string[]; + Server.GetFields(ids, action((fields: { [id: string]: Field }) => this.userWorkspaces = ids.map(id => fields[id] as Document))); + }); + } }); // bcz: strangely, we need a timeout to prevent exceptions/issues initializing GoldenLayout (the rendering engine for Main Container) setTimeout(() => { let freeformDoc = Documents.FreeformDocument([], { x: 0, y: 400, title: "mini collection" }); - var dockingLayout = { content: [{ type: 'row', content: [CollectionDockingView.makeDocumentConfig(freeformDoc)] }] }; mainDoc.SetText(KeyStore.Data, JSON.stringify(dockingLayout)); mainDoc.Set(KeyStore.ActiveFrame, freeformDoc); diff --git a/src/server/authentication/controllers/WorkspacesMenu.tsx b/src/server/authentication/controllers/WorkspacesMenu.tsx index 00de34d7a..70c37774c 100644 --- a/src/server/authentication/controllers/WorkspacesMenu.tsx +++ b/src/server/authentication/controllers/WorkspacesMenu.tsx @@ -11,7 +11,7 @@ import { Field } from '../../../fields/Field'; export interface WorkspaceMenuProps { active: Document; open: (workspace: Document) => void; - new: () => void; + new: (init: boolean) => void; allWorkspaces: Document[]; } @@ -28,7 +28,7 @@ export class WorkspacesMenu extends React.Component<WorkspaceMenuProps> { @action addNewWorkspace() { - this.props.new(); + this.props.new(false); this.toggle(); } |