diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-29 14:38:09 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-29 14:38:09 -0700 |
commit | 7ced683e2c0bbc1b666e0b01799788810cebfd98 (patch) | |
tree | 6997389e629fe6ac00ecfebedbd631266b1334f6 /src | |
parent | fabb86b78874a38619d821b315eaf9ce204e1afe (diff) |
keep trying to scroll until annotations have loaded & scrolling is successful
Diffstat (limited to 'src')
-rw-r--r-- | src/client/apis/hypothesis/HypothesisUtils.ts | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts index e15620a91..e245552b1 100644 --- a/src/client/apis/hypothesis/HypothesisUtils.ts +++ b/src/client/apis/hypothesis/HypothesisUtils.ts @@ -69,9 +69,23 @@ export namespace Hypothesis { }; export const scrollToAnnotation = (annotationId: string) => { - document.dispatchEvent(new CustomEvent("scrollToAnnotation", { - detail: annotationId, - bubbles: true - })); + var success = false; + const onSuccess = () => { + console.log("scroll success!!"); + document.removeEventListener('scrollSuccess', onSuccess); + clearTimeout(interval); + success = true; + }; + + const interval = setInterval(() => { // keep trying to scroll every 200ms until annotations have loaded and scrolling is successful + console.log("send scroll"); + document.dispatchEvent(new CustomEvent('scrollToAnnotation', { + detail: annotationId, + bubbles: true + })); + }, 200); + + document.addEventListener('scrollSuccess', onSuccess); // listen for success message from client + setTimeout(() => !success && clearTimeout(interval), 10000); // give up if no success after 10s }; }
\ No newline at end of file |