diff options
author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-03-16 23:16:26 -0400 |
---|---|---|
committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-03-16 23:16:26 -0400 |
commit | 8601bcbb46c80282d1fac6863544f9c72050ebd4 (patch) | |
tree | 6c73456d3ac26b5d1180a0ee136b1150407d8ae3 | |
parent | 972d7c28f2f99ee0fa8f0de521e7798edc4fd556 (diff) |
Fixed server bug
-rw-r--r-- | src/client/Server.ts | 30 | ||||
-rw-r--r-- | src/client/SocketStub.ts | 1 | ||||
-rw-r--r-- | src/client/documents/Documents.ts | 2 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 6 |
4 files changed, 34 insertions, 5 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts index f0cf0bb9b..f2d7de75c 100644 --- a/src/client/Server.ts +++ b/src/client/Server.ts @@ -40,8 +40,8 @@ export class Server { return this.ClientFieldsCached.get(fieldid); }, (field, reaction) => { if (field !== "<Waiting>") { - callback(field) reaction.dispose() + callback(field) } }) } @@ -49,14 +49,38 @@ export class Server { } public static GetFields(fieldIds: FieldId[], callback: (fields: { [id: string]: Field }) => any) { - SocketStub.SEND_FIELDS_REQUEST(fieldIds, (fields) => { + let neededFieldIds: FieldId[] = []; + let waitingFieldIds: FieldId[] = []; + let existingFields: { [id: string]: Field } = {}; + for (let id of fieldIds) { + let field = this.ClientFieldsCached.get(id); + if (!field) { + neededFieldIds.push(id); + } else if (field === FieldWaiting) { + waitingFieldIds.push(id); + } else { + existingFields[id] = field; + } + } + SocketStub.SEND_FIELDS_REQUEST(neededFieldIds, (fields) => { for (let key in fields) { let field = fields[key]; if (!this.ClientFieldsCached.has(field.Id)) { this.ClientFieldsCached.set(field.Id, field) } } - callback(fields) + reaction(() => { + return waitingFieldIds.map(this.ClientFieldsCached.get); + }, (cachedFields, reaction) => { + if (!cachedFields.some(field => !field || field === FieldWaiting)) { + reaction.dispose(); + for (let field of cachedFields) { + let realField = field as Field; + existingFields[realField.Id] = realField; + } + callback({ ...fields, ...existingFields }) + } + }, { fireImmediately: true }) }); } diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts index 18df4ca0a..a0b89b7c9 100644 --- a/src/client/SocketStub.ts +++ b/src/client/SocketStub.ts @@ -7,6 +7,7 @@ import { Utils } from "../Utils"; import { Server } from "./Server"; import { ServerUtils } from "../server/ServerUtil"; +//TODO tfs: I think it might be cleaner to not have SocketStub deal with turning what the server gives it into Fields (in other words not call ServerUtils.FromJson), and leave that for the Server class. export class SocketStub { static FieldStore: ObservableMap<FieldId, Field> = new ObservableMap(); diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 7b6409a62..bec4dd697 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -175,7 +175,7 @@ export namespace Documents { return SetInstanceOptions(GetAudioPrototype(), options, [new URL(url), AudioField]); } export function TextDocument(options: DocumentOptions = {}) { - return SetInstanceOptions(GetTextPrototype(), options, ["", RichTextField]); + return SetInstanceOptions(GetTextPrototype(), options, ["", TextField]); } export function PdfDocument(url: string, options: DocumentOptions = {}) { return SetInstanceOptions(GetPdfPrototype(), options, [new URL(url), PDFField]); diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 3c1f98ef8..7a43c34d0 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -188,6 +188,9 @@ export class DocumentView extends React.Component<DocumentViewProps> { SelectionManager.SelectDoc(this, e.ctrlKey); } } + stopPropogation = (e: React.SyntheticEvent) => { + e.stopPropagation(); + } deleteClicked = (): void => { if (this.props.RemoveDocument) { @@ -338,7 +341,8 @@ export class DocumentView extends React.Component<DocumentViewProps> { }} onDrop={this.onDrop} onContextMenu={this.onContextMenu} - onPointerDown={this.onPointerDown} > + onPointerDown={this.onPointerDown} + onPointerUp={this.stopPropogation} > <DocumentContentsView {...this.getProps} /> </div> ) |