aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionViewBase.tsx
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-03-18 11:48:24 -0400
committerbob <bcz@cs.brown.edu>2019-03-18 11:48:24 -0400
commit8418b842b16da68150243e1750aa8b40eb8a8792 (patch)
treeec92fd749aa93d90f889aa26e3233506973e7c9d /src/client/views/collections/CollectionViewBase.tsx
parentd5304e13839830c60c0c5698849535b0605e3c32 (diff)
fixed removing from schemas. fixed dragging link button to move quickly. cleaned up drag/drop code a little
Diffstat (limited to 'src/client/views/collections/CollectionViewBase.tsx')
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx36
1 files changed, 12 insertions, 24 deletions
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 3d1a76a07..0358b5907 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -27,7 +27,7 @@ export interface CollectionViewProps {
}
export interface SubCollectionViewProps extends CollectionViewProps {
active: () => boolean;
- addDocument: (doc: Document) => void;
+ addDocument: (doc: Document, allowDuplicates: boolean) => void;
removeDocument: (doc: Document) => boolean;
CollectionView: CollectionView;
}
@@ -46,28 +46,16 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
@undoBatch
@action
protected drop(e: Event, de: DragManager.DropEvent) {
- let docToAlias = de.data["documentToAlias"];
- let docView = de.data["documentView"];
- let doc = docToAlias ? docToAlias.CreateAlias() : de.data["document"];
- if (docToAlias) {
- [KeyStore.Width, KeyStore.Height].map(key =>
- docToAlias.GetTAsync(key, NumberField, (f: Opt<NumberField>) => {
- if (f) {
- doc.SetNumber(key, f.Data)
- }
- })
- );
- de.data["document"] = doc;
- this.props.addDocument(doc);
- } else if (docView) {
- if (doc && docView.props.RemoveDocument && docView.props.ContainingCollectionView !== this.props.CollectionView) {
- docView.props.RemoveDocument(doc);
- this.props.removeDocument(doc); // bcz: not good -- want to check if it's there and then add if it isn't
- this.props.addDocument(doc);
+ let dropped = de.data["droppedDocument"];
+ if (dropped) {
+ if (de.data["aliasOnDrop"]) {
+ let dragged = de.data["draggedDocument"];
+ [KeyStore.Width, KeyStore.Height, KeyStore.CurPage].map(key =>
+ dragged.GetTAsync(key, NumberField, (f: Opt<NumberField>) => f ? dropped.SetNumber(key, f.Data) : null));
+ } else if (de.data["removeDocument"]) {
+ de.data["removeDocument"](this.props.CollectionView);
}
- } else if (doc) {
- this.props.removeDocument(doc); // bcz: not good -- want to check if it's there and then add if it isn't
- this.props.addDocument(doc);
+ this.props.addDocument(dropped, false);
}
e.stopPropagation();
}
@@ -89,7 +77,7 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
console.log("not good");
let htmlDoc = Documents.HtmlDocument(html, { ...options, width: 300, height: 300 });
htmlDoc.SetText(KeyStore.DocumentText, text);
- this.props.addDocument(htmlDoc);
+ this.props.addDocument(htmlDoc, false);
return;
}
@@ -99,7 +87,7 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
const upload = window.location.origin + "/upload";
let item = e.dataTransfer.items[i];
if (item.kind === "string" && item.type.indexOf("uri") != -1) {
- e.dataTransfer.items[i].getAsString(action((s: string) => this.props.addDocument(Documents.WebDocument(s, options))))
+ e.dataTransfer.items[i].getAsString(action((s: string) => this.props.addDocument(Documents.WebDocument(s, options), false)))
}
let type = item.type
console.log(type)