From 84cf9d6536b0e7eb75cec22bc69a11937b7c47b1 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 10 Mar 2022 13:58:38 -0500
Subject: added prop when thumbnail is shown for a document so componentView
 can choose not to render.  fixed pdf views to not generate gray box when
 first transitioning from thumb to live view.

---
 src/client/views/nodes/DocumentView.tsx | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

(limited to 'src/client/views/nodes/DocumentView.tsx')

diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 274ccb807..7092b335c 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -109,6 +109,7 @@ export interface DocumentViewSharedProps {
     fitContentsToDoc?: () => boolean; // used by freeformview to fit its contents to its panel. corresponds to _fitToBox property on a Document
     ContainingCollectionView: Opt<CollectionView>;
     ContainingCollectionDoc: Opt<Doc>;
+    thumbShown?: () => boolean;
     setContentView?: (view: DocComponentView) => any;
     CollectionFreeFormDocumentView?: () => CollectionFreeFormDocumentView;
     PanelWidth: () => number;
@@ -838,6 +839,9 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
             this._componentView?.isAnyChildContentActive?.() ||
             this.props.isContentActive()) ? true : undefined;
     }
+    @observable _retryThumb = 1;
+    thumbShown = () => !this.props.isSelected() && LightboxView.LightboxDoc !== this.rootDoc && this.thumb &&
+        !this._componentView?.isAnyChildContentActive?.() ? true : false;
     @computed get contents() {
         TraceMobx();
         const audioView = !this.layoutDoc._showAudio ? (null) :
@@ -851,11 +855,17 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
                 pointerEvents: this.props.pointerEvents as any ? this.props.pointerEvents as any : (this.rootDoc.type !== DocumentType.INK && ((this.props.contentPointerEvents as any) || (this.isContentActive())) ? "all" : "none"),
                 height: this.headerMargin ? `calc(100% - ${this.headerMargin}px)` : undefined,
             }}>
-            {!this.thumb ? (null) :
+            {!this._retryThumb || !this.thumbShown() ? (null) :
                 <img style={{ background: "white", top: 0, position: "absolute" }} src={this.thumb} // + '?d=' + (new Date()).getTime()}
-                    width={this.props.PanelWidth()} height={this.props.PanelHeight()} />}
-            <DocumentContentsView key={1} {...this.props}
+                    width={this.props.PanelWidth()} height={this.props.PanelHeight()}
+                    onError={(e: any) => {
+                        setTimeout(action(() => this._retryThumb = 0), 0);
+                        setTimeout(action(() => this._retryThumb = 1), 150);
+                    }} />}
+            <DocumentContentsView key={1}
+                {...this.props}
                 docViewPath={this.props.viewPath}
+                thumbShown={this.thumbShown}
                 setContentView={this.setContentView}
                 scaling={this.contentScaling}
                 PanelHeight={this.panelHeight}
-- 
cgit v1.2.3-70-g09d2

