From bd6b5a81480f7f56a65c13954e080281279b6627 Mon Sep 17 00:00:00 2001
From: Melissa Zhang <mzhang19096@gmail.com>
Date: Tue, 4 Aug 2020 16:53:36 -0700
Subject: "added invisibleDoc and simulated clicks to load annotations"

---
 src/client/views/collections/CollectionSubView.tsx | 26 ++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)

(limited to 'src/client/views/collections/CollectionSubView.tsx')

diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 5906282f1..b66da27b4 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -346,15 +346,22 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
                 // }
             }
             if (uriList) {
-                this.addDocument(Docs.Create.WebDocument(uriList, {
-                    ...options,
-                    title: uriList,
-                    _width: 400,
-                    _height: 315,
-                    _nativeWidth: 850,
-                    _nativeHeight: 962,
-                    UseCors: true
-                }));
+                const existingWebDoc = await Hypothesis.findWebDoc(uriList);
+
+                if (existingWebDoc) {
+                    this.addDocument(Doc.MakeAlias(existingWebDoc));
+                } else {
+                    const cleanedUri = uriList.split("#annotations:")[0]; // clean hypothes.is URLs that scroll directly to an annotation
+                    this.addDocument(Docs.Create.WebDocument(uriList, {
+                        ...options,
+                        title: cleanedUri,
+                        _width: 400,
+                        // _height: 315,
+                        _nativeWidth: 850,
+                        _nativeHeight: 962,
+                        UseCors: true
+                    }));
+                }
                 return;
             }
 
@@ -437,4 +444,5 @@ import { CollectionView, CollectionViewType } from "./CollectionView";
 import { SelectionManager } from "../../util/SelectionManager";
 import { OverlayView } from "../OverlayView";
 import { setTimeout } from "timers";
+import { Hypothesis } from "../../apis/hypothesis/HypothesisUtils";
 
-- 
cgit v1.2.3-70-g09d2

