diff options
| author | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-05-08 23:16:24 -0400 |
|---|---|---|
| committer | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-05-08 23:16:24 -0400 |
| commit | 508410d810f61b8f8602dedbbba3e0736c1f5ba3 (patch) | |
| tree | b6de0f335ed187f7e795025ba9a304b3146fc6a2 /src/client/views/collections/CollectionBaseView.tsx | |
| parent | 086391b7e45ed4b3cb29602a776f5812f142fff2 (diff) | |
| parent | 890d43c23c5aaafc8ebc2978cd1ad2e19bfcd830 (diff) | |
Working implementation of remote cursors
Diffstat (limited to 'src/client/views/collections/CollectionBaseView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionBaseView.tsx | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/client/views/collections/CollectionBaseView.tsx b/src/client/views/collections/CollectionBaseView.tsx index 76adfcdcd..14b92af48 100644 --- a/src/client/views/collections/CollectionBaseView.tsx +++ b/src/client/views/collections/CollectionBaseView.tsx @@ -95,17 +95,20 @@ export class CollectionBaseView extends React.Component<CollectionViewProps> { if (!this.createsCycle(doc, props.Document)) { //TODO This won't create the field if it doesn't already exist const value = Cast(props.Document[props.fieldKey], listSpec(Doc)); + let alreadyAdded = true; if (value !== undefined) { - if (allowDuplicates || !value.some(v => v[Id] === doc[Id])) { + if (allowDuplicates || !value.some(v => v instanceof Doc && v[Id] === doc[Id])) { + alreadyAdded = false; value.push(doc); } } else { - this.props.Document[this.props.fieldKey] = new List([doc]); + alreadyAdded = false; + Doc.SetOnPrototype(this.props.Document, this.props.fieldKey, new List([doc])); } // set the ZoomBasis only if hasn't already been set -- bcz: maybe set/resetting the ZoomBasis should be a parameter to addDocument? - if (this.collectionViewType === CollectionViewType.Freeform || this.collectionViewType === CollectionViewType.Invalid) { + if (!alreadyAdded && (this.collectionViewType === CollectionViewType.Freeform || this.collectionViewType === CollectionViewType.Invalid)) { let zoom = NumCast(this.props.Document.scale, 1); - doc.zoomBasis = zoom; + Doc.SetOnPrototype(doc, "zoomBasis", zoom); } } return true; @@ -118,7 +121,8 @@ export class CollectionBaseView extends React.Component<CollectionViewProps> { const value = Cast(props.Document[props.fieldKey], listSpec(Doc), []); let index = -1; for (let i = 0; i < value.length; i++) { - if (value[i][Id] === doc[Id]) { + let v = value[i]; + if (v instanceof Doc && v[Id] === doc[Id]) { index = i; break; } |
