aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-03-18 12:57:36 -0400
committerbob <bcz@cs.brown.edu>2019-03-18 12:57:36 -0400
commitbe117e38a63a558684baa69f719787f11dfc3be3 (patch)
tree8275d70be6aa728de3fea9af76b9422464143227 /src/client/views/collections/CollectionView.tsx
parent8acbb6e31d913982e06b8498078b90bf99c18600 (diff)
parent861614569c2d72e0ee9a6a698f3978f609a3b2bc (diff)
Merge branch 'master' into authentication
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 40acf466e..303099c16 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -36,7 +36,7 @@ export class CollectionView extends React.Component<CollectionViewProps> {
@observable
public SelectedDocs: FieldId[] = [];
public active: () => boolean = () => CollectionView.Active(this);
- addDocument = (doc: Document): void => { CollectionView.AddDocument(this.props, doc); }
+ addDocument = (doc: Document, allowDuplicates: boolean): void => { CollectionView.AddDocument(this.props, doc, allowDuplicates); }
removeDocument = (doc: Document): boolean => { return CollectionView.RemoveDocument(this.props, doc); }
get subView() { return CollectionView.SubView(this); }
@@ -48,12 +48,13 @@ export class CollectionView extends React.Component<CollectionViewProps> {
}
@action
- public static AddDocument(props: CollectionViewProps, doc: Document) {
+ public static AddDocument(props: CollectionViewProps, doc: Document, allowDuplicates: boolean) {
doc.SetNumber(KeyStore.Page, props.Document.GetNumber(KeyStore.CurPage, -1));
if (props.Document.Get(props.fieldKey) instanceof Field) {
//TODO This won't create the field if it doesn't already exist
const value = props.Document.GetData(props.fieldKey, ListField, new Array<Document>())
- value.push(doc);
+ if (!value.some(v => v.Id == doc.Id) || allowDuplicates)
+ value.push(doc);
} else {
props.Document.SetOnPrototype(props.fieldKey, new ListField([doc]));
}