From f4a01b9b394a5bdc48e57923567249bb05cb71ff Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Fri, 8 Mar 2019 00:11:04 -0500 Subject: Close to refactor --- .../authentication/controllers/WorkspacesMenu.tsx | 56 ++++++---------------- 1 file changed, 15 insertions(+), 41 deletions(-) (limited to 'src/server/authentication/controllers/WorkspacesMenu.tsx') diff --git a/src/server/authentication/controllers/WorkspacesMenu.tsx b/src/server/authentication/controllers/WorkspacesMenu.tsx index b565af193..ebc4f5a10 100644 --- a/src/server/authentication/controllers/WorkspacesMenu.tsx +++ b/src/server/authentication/controllers/WorkspacesMenu.tsx @@ -4,62 +4,37 @@ import { observable, action, configure, reaction, computed, ObservableMap, runIn import { observer } from "mobx-react"; import * as request from 'request' import './WorkspacesMenu.css' +import { Document } from '../../../fields/Document'; +import { Server } from '../../../client/Server'; +import { Field } from '../../../fields/Field'; export interface WorkspaceMenuProps { - active: string; - load: (workspaceId: string) => void; - new: () => string; + active: Document; + open: (workspace: Document) => void; + new: () => void; + allWorkspaces: Document[]; } @observer export class WorkspacesMenu extends React.Component { static Instance: WorkspacesMenu; @observable private workspacesExposed: boolean = false; - @observable private workspaceIds: Array = []; - @observable private selectedWorkspaceId: string = ""; constructor(props: WorkspaceMenuProps) { super(props); WorkspacesMenu.Instance = this; - this.loadExistingWorkspace = this.loadExistingWorkspace.bind(this); this.addNewWorkspace = this.addNewWorkspace.bind(this); - this.selectedWorkspaceId = this.props.active; } @action addNewWorkspace() { - let newId = this.props.new(); - this.selectedWorkspaceId = newId; - this.props.load(newId); + this.props.new(); this.toggle(); } - @action - loadExistingWorkspace = (e: React.MouseEvent) => { - let id = e.currentTarget.innerHTML; - this.props.load(id); - this.selectedWorkspaceId = id; - } - @action toggle() { - if (this.workspacesExposed) { - this.workspacesExposed = !this.workspacesExposed; - } else { - request.get(window.location.origin + "/getAllWorkspaceIds", this.idCallback) - } - } - - @action.bound - idCallback: request.RequestCallback = (error, response, body) => { - this.workspaceIds = []; - let ids: Array = JSON.parse(body) as Array; - if (ids) { - for (let i = 0; i < ids.length; i++) { - this.workspaceIds.push(ids[i]); - } - this.workspacesExposed = !this.workspacesExposed; - } + this.workspacesExposed = !this.workspacesExposed; } render() { @@ -78,8 +53,7 @@ export class WorkspacesMenu extends React.Component { transition: "all 1s ease", zIndex: 15, padding: 10, - }} - > + }}> { }} onClick={this.addNewWorkspace} /> - {this.workspaceIds.map(s => + {this.props.allWorkspaces.map(s =>
  • {s}
  • + onClick={() => this.props.open(s)} + >{s.Title} )} ); -- cgit v1.2.3-70-g09d2