aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Network.ts46
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts17
-rw-r--r--src/client/documents/Documents.ts22
-rw-r--r--src/client/util/Import & Export/DirectoryImportBox.tsx5
-rw-r--r--src/client/views/nodes/DocumentView.tsx7
5 files changed, 55 insertions, 42 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts
index cb46105f8..75ccb5e99 100644
--- a/src/client/Network.ts
+++ b/src/client/Network.ts
@@ -2,24 +2,32 @@ import { Utils } from "../Utils";
import { CurrentUserUtils } from "../server/authentication/models/current_user_utils";
import requestPromise = require('request-promise');
-export async function PostToServer(relativeRoute: string, body?: any) {
- let options = {
- uri: Utils.prepend(relativeRoute),
- method: "POST",
- headers: { userId: CurrentUserUtils.id },
- body,
- json: true
- };
- return requestPromise.post(options);
-}
+export namespace Identified {
+
+ export async function FetchFromServer(relativeRoute: string) {
+ return (await fetch(relativeRoute, { headers: { userId: CurrentUserUtils.id } })).text();
+ }
+
+ export async function PostToServer(relativeRoute: string, body?: any) {
+ let options = {
+ uri: Utils.prepend(relativeRoute),
+ method: "POST",
+ headers: { userId: CurrentUserUtils.id },
+ body,
+ json: true
+ };
+ return requestPromise.post(options);
+ }
+
+ export async function PostFormDataToServer(relativeRoute: string, formData: FormData) {
+ const parameters = {
+ method: 'POST',
+ headers: { userId: CurrentUserUtils.id },
+ body: formData,
+ };
+ const response = await fetch(relativeRoute, parameters);
+ const text = await response.json();
+ return text;
+ }
-export async function PostFormDataToServer(relativeRoute: string, formData: FormData) {
- const parameters = {
- method: 'POST',
- headers: { userId: CurrentUserUtils.id },
- body: formData,
- };
- const response = await fetch(relativeRoute, parameters);
- const text = await response.json();
- return text;
} \ No newline at end of file
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index b1b29210a..29cc042b6 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -14,11 +14,14 @@ import { NewMediaItemResult, MediaItem } from "../../../server/apis/google/Share
import { AssertionError } from "assert";
import { DocumentView } from "../../views/nodes/DocumentView";
import { DocumentManager } from "../../util/DocumentManager";
-import { PostToServer } from "../../Network";
+import { Identified } from "../../Network";
export namespace GooglePhotos {
- const endpoint = async () => new Photos(await PostToServer(RouteStore.googlePhotosAccessToken));
+ const endpoint = async () => {
+ const accessToken = await Identified.FetchFromServer(RouteStore.googlePhotosAccessToken);
+ return new Photos(accessToken);
+ };
export enum MediaType {
ALL_MEDIA = 'ALL_MEDIA',
@@ -296,7 +299,7 @@ export namespace GooglePhotos {
};
export const WriteMediaItemsToServer = async (body: { mediaItems: any[] }): Promise<UploadInformation[]> => {
- const uploads = await PostToServer(RouteStore.googlePhotosMediaDownload, body);
+ const uploads = await Identified.PostToServer(RouteStore.googlePhotosMediaDownload, body);
return uploads;
};
@@ -316,7 +319,7 @@ export namespace GooglePhotos {
album = await Create.Album(album.title);
}
const media: MediaInput[] = [];
- sources.forEach(source => {
+ for (let source of sources) {
const data = Cast(Doc.GetProto(source).data, ImageField);
if (!data) {
return;
@@ -324,11 +327,11 @@ export namespace GooglePhotos {
const url = data.url.href;
const target = Doc.MakeAlias(source);
const description = parseDescription(target, descriptionKey);
- DocumentView.makeCustomViewClicked(target, undefined);
+ await DocumentView.makeCustomViewClicked(target, undefined);
media.push({ url, description });
- });
+ }
if (media.length) {
- const uploads: NewMediaItemResult[] = await PostToServer(RouteStore.googlePhotosMediaUpload, { media, album });
+ const uploads: NewMediaItemResult[] = await Identified.PostToServer(RouteStore.googlePhotosMediaUpload, { media, album });
return uploads;
}
};
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index a7a006f47..0369e89a6 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -337,16 +337,18 @@ export namespace Docs {
let extension = path.extname(target);
target = `${target.substring(0, target.length - extension.length)}_o${extension}`;
}
- requestImageSize(target)
- .then((size: any) => {
- let aspect = size.height / size.width;
- if (!inst.proto!.nativeWidth) {
- inst.proto!.nativeWidth = size.width;
- }
- inst.proto!.nativeHeight = Number(inst.proto!.nativeWidth!) * aspect;
- inst.proto!.height = NumCast(inst.proto!.width) * aspect;
- })
- .catch((err: any) => console.log(err));
+ if (target !== "http://www.cs.brown.edu/") {
+ requestImageSize(target)
+ .then((size: any) => {
+ let aspect = size.height / size.width;
+ if (!inst.proto!.nativeWidth) {
+ inst.proto!.nativeWidth = size.width;
+ }
+ inst.proto!.nativeHeight = Number(inst.proto!.nativeWidth!) * aspect;
+ inst.proto!.height = NumCast(inst.proto!.width) * aspect;
+ })
+ .catch((err: any) => console.log(err));
+ }
return inst;
}
export function PresDocument(initial: List<Doc> = new List(), options: DocumentOptions = {}) {
diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx
index d0291aec4..de5287456 100644
--- a/src/client/util/Import & Export/DirectoryImportBox.tsx
+++ b/src/client/util/Import & Export/DirectoryImportBox.tsx
@@ -21,7 +21,7 @@ import { GooglePhotos } from "../../apis/google_docs/GooglePhotosClientUtils";
import { SchemaHeaderField } from "../../../new_fields/SchemaHeaderField";
import "./DirectoryImportBox.scss";
import BatchedArray from "array-batcher";
-import { PostFormDataToServer } from "../../Network";
+import { Identified } from "../../Network";
const unsupported = ["text/html", "text/plain"];
interface FileResponse {
@@ -114,7 +114,7 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
formData.append(Utils.GenerateGuid(), file);
});
- const responses = await PostFormDataToServer(RouteStore.upload, formData);
+ const responses = await Identified.PostFormDataToServer(RouteStore.upload, formData);
runInAction(() => this.completed += batch.length);
return responses as FileResponse[];
});
@@ -279,7 +279,6 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
}} />
<label
htmlFor={"selector"}
- onClick={console.log}
style={{
opacity: isEditing ? 0 : 1,
pointerEvents: isEditing ? "none" : "all",
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 78fcaad27..a6d350ca2 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -295,10 +295,10 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
deleteClicked = (): void => { SelectionManager.DeselectAll(); this.props.removeDocument && this.props.removeDocument(this.props.Document); }
@undoBatch
- static makeNativeViewClicked = (doc: Doc): void => { swapViews(doc, "layoutNative", "layoutCustom"); }
+ static makeNativeViewClicked = async (doc: Doc): Promise<void> => swapViews(doc, "layoutNative", "layoutCustom")
- @undoBatch
static makeCustomViewClicked = async (doc: Doc, dataDoc: Opt<Doc>) => {
+ const batch = UndoManager.StartBatch("CustomViewClicked");
if (doc.layoutCustom === undefined) {
Doc.GetProto(dataDoc || doc).layoutNative = Doc.MakeTitled("layoutNative");
await swapViews(doc, "", "layoutNative");
@@ -320,8 +320,9 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
Doc.ApplyTemplateTo(docTemplate, doc, undefined);
Doc.GetProto(dataDoc || doc).layoutCustom = Doc.MakeTitled("layoutCustom");
} else {
- swapViews(doc, "layoutCustom", "layoutNative");
+ await swapViews(doc, "layoutCustom", "layoutNative");
}
+ batch.end();
}
@undoBatch