aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-03-18 06:57:25 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-03-18 06:57:25 -0400
commit4354f7f9d7a62a4193ac8f84380722db75d806d8 (patch)
tree7a07cedb68d0606511748166b8803a69f4528023 /src
parent7859d3c9902d6d15666cce6a93a24cfba6ffdf32 (diff)
Fixed image upload to mostly work with authentication
Diffstat (limited to 'src')
-rw-r--r--src/client/views/Main.tsx16
-rw-r--r--src/mobile/ImageUpload.tsx53
2 files changed, 37 insertions, 32 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index d0f84f779..26a07fdfe 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -176,13 +176,15 @@ export class Main extends React.Component {
this.mainContainer.GetTAsync(KeyStore.ActiveFrame, Document, field => this.mainfreeform = field);
this.mainContainer.GetTAsync(KeyStore.OptionalRightCollection, Document, col => {
// if there is a pending doc, and it has new data, show it (syip: we use a timeout to prevent collection docking view from being uninitialized)
- if (col) {
- col.GetTAsync<ListField<Document>>(KeyStore.Data, ListField, (f: Opt<ListField<Document>>) => {
- if (f && f.Data.length > 0) {
- CollectionDockingView.Instance.AddRightSplit(col);
- }
- })
- }
+ setTimeout(() => {
+ if (col) {
+ col.GetTAsync<ListField<Document>>(KeyStore.Data, ListField, (f: Opt<ListField<Document>>) => {
+ if (f && f.Data.length > 0) {
+ CollectionDockingView.Instance.AddRightSplit(col);
+ }
+ })
+ }
+ }, 100);
});
}
diff --git a/src/mobile/ImageUpload.tsx b/src/mobile/ImageUpload.tsx
index 292a3a035..16808a598 100644
--- a/src/mobile/ImageUpload.tsx
+++ b/src/mobile/ImageUpload.tsx
@@ -1,15 +1,15 @@
import * as ReactDOM from 'react-dom';
import React = require('react');
import "./ImageUpload.scss"
-import { action, runInAction } from "mobx";
-import { type } from 'os';
-import { Documents } from '../client/documents/Documents';
import { Document } from '../fields/Document';
+import { KeyStore } from '../fields/KeyStore';
import { Server } from '../client/Server';
-import { Opt, Field } from '../fields/Field';
+import { Documents } from '../client/documents/Documents';
import { ListField } from '../fields/ListField';
-import { KeyStore } from '../fields/KeyStore';
import { ImageField } from '../fields/ImageField';
+import request = require('request');
+import { ServerUtils } from '../server/ServerUtil';
+import { RouteStore } from '../server/RouteStore';
@@ -20,7 +20,6 @@ import { ImageField } from '../fields/ImageField';
// imgInput.click();
// }
// }
-const pendingDocId = "pending-doc"
const onFileLoad = (file: any) => {
let imgPrev = document.getElementById("img_preview")
@@ -40,32 +39,36 @@ const onFileLoad = (file: any) => {
}).then(json => {
json.map((file: any) => {
let path = window.location.origin + file
- runInAction(() => {
- var doc: Document = Documents.ImageDocument(path, { nativeWidth: 200, width: 200 })
- doc.GetTAsync(KeyStore.Data, ImageField, (i) => {
- if (i) {
- document.getElementById("message")!.innerText = i.Data.href;
- }
- })
- Server.GetField(pendingDocId, (res: Opt<Field>) => {
- if (res) {
- if (res instanceof Document) {
- res.GetOrCreateAsync(KeyStore.Data, ListField, (f: ListField<Document>) => {
- f.Data.push(doc)
- })
+ var doc: Document = Documents.ImageDocument(path, { nativeWidth: 200, width: 200 })
+ doc.GetTAsync(KeyStore.Data, ImageField, (i) => {
+ if (i) {
+ document.getElementById("message")!.innerText = i.Data.href;
+ }
+ })
+ request.get(ServerUtils.prepend(RouteStore.getActiveWorkspace), (error, response, body) => {
+ if (body) {
+ Server.GetField(body, field => {
+ if (field instanceof Document) {
+ field.GetTAsync(KeyStore.OptionalRightCollection, Document,
+ pending => {
+ if (pending) {
+ pending.GetOrCreateAsync(KeyStore.Data, ListField, list => {
+ list.Data.push(doc);
+ })
+ }
+ })
}
}
- })
+ );
+ }
})
+ // console.log(window.location.origin + file[0])
+
+ //imgPrev.setAttribute("src", window.location.origin + files[0].name)
})
})
- // console.log(window.location.origin + file[0])
-
- //imgPrev.setAttribute("src", window.location.origin + files[0].name)
}
}
-
-
}
ReactDOM.render((