From b2cfb0061ce74d095b176a830c3bc654dbaa783b Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Fri, 22 Mar 2019 02:58:15 -0400 Subject: Better typechecking and more Promises --- src/client/documents/Documents.ts | 5 ++--- src/client/views/Main.tsx | 16 +++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index cf6d7d503..96a7332aa 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -63,15 +63,14 @@ export namespace Documents { const videoProtoId = "videoProto" const audioProtoId = "audioProto"; - export function initProtos(callback: () => void) { - Server.GetFields([collProtoId, textProtoId, imageProtoId], (fields) => { + export function initProtos(): Promise { + return Server.GetFields([textProtoId, histoProtoId, collProtoId, imageProtoId, webProtoId, kvpProtoId]).then(fields => { textProto = fields[textProtoId] as Document; histoProto = fields[histoProtoId] as Document; collProto = fields[collProtoId] as Document; imageProto = fields[imageProtoId] as Document; webProto = fields[webProtoId] as Document; kvpProto = fields[kvpProtoId] as Document; - callback(); }); } function assignOptions(doc: Document, options: DocumentOptions): Document { diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index d2ba6998c..fdbad6ce1 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -23,7 +23,7 @@ import "./Main.scss"; import { observer } from 'mobx-react'; import { InkingControl } from './InkingControl'; import { RouteStore } from '../../server/RouteStore'; -import { library } from '@fortawesome/fontawesome-svg-core'; +import { library, IconName } from '@fortawesome/fontawesome-svg-core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFont } from '@fortawesome/free-solid-svg-icons'; import { faImage } from '@fortawesome/free-solid-svg-icons'; @@ -109,7 +109,7 @@ export class Main extends React.Component { library.add(faTree); this.initEventListeners(); - Documents.initProtos(() => this.initAuthenticationRouters()); + this.initAuthenticationRouters(); this.initializeNorthstar(); } @@ -256,7 +256,7 @@ export class Main extends React.Component { let addWebNode = action(() => Documents.WebDocument(weburl, { width: 200, height: 200, title: "a sample web page" })); let addAudioNode = action(() => Documents.AudioDocument(audiourl, { width: 200, height: 200, title: "audio node" })) - let btns = [ + let btns: [React.RefObject, IconName, string, () => Document][] = [ [React.createRef(), "font", "Add Textbox", addTextNode], [React.createRef(), "image", "Add Image", addImageNode], [React.createRef(), "file-pdf", "Add PDF", addPDFNode], @@ -277,9 +277,9 @@ export class Main extends React.Component {
    {btns.map(btn => -
  • }> -
  • )}
@@ -375,6 +375,8 @@ export class Main extends React.Component { } } -CurrentUserUtils.loadCurrentUser().then(() => { +Documents.initProtos().then(() => { + return CurrentUserUtils.loadCurrentUser() +}).then(() => { ReactDOM.render(
, document.getElementById('root')); }); -- cgit v1.2.3-70-g09d2