From a6459d3641586d87794ea5eee51185a1547655c7 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 8 Apr 2020 17:40:32 +0000 Subject: [PATCH] Mobile: Fixes #2941: Fixed resource download auto mode --- ElectronClient/gui/ResourceScreen.tsx | 108 +++++++++--------- .../lib/components/note-body-viewer.js | 16 ++- 2 files changed, 71 insertions(+), 53 deletions(-) diff --git a/ElectronClient/gui/ResourceScreen.tsx b/ElectronClient/gui/ResourceScreen.tsx index 0cc046a5d2..d1543cd9d3 100644 --- a/ElectronClient/gui/ResourceScreen.tsx +++ b/ElectronClient/gui/ResourceScreen.tsx @@ -81,34 +81,36 @@ const ResourceTable: React.FC = (props: ResourceTable) => { fontWeight: 'bold', }; - return - - - - - - - - - - {props.resources.map((resource: Resource, index: number) => - - - - - + return ( +
{_('Title')} {sortOrderEngagedMarker('name')}{_('Size')} {sortOrderEngagedMarker('size')}{_('ID')}{_('Action')}
- props.onResourceClick(resource)}>{resource.title || `(${_('Untitled')})`} - - {prettyBytes(resource.size)}{resource.id} - -
+ + + + + + - )} - -
{_('Title')} {sortOrderEngagedMarker('name')}{_('Size')} {sortOrderEngagedMarker('size')}{_('ID')}{_('Action')}
; + + + {props.resources.map((resource: Resource, index: number) => + + + props.onResourceClick(resource)}>{resource.title || `(${_('Untitled')})`} + + + {prettyBytes(resource.size)} + {resource.id} + + + + + )} + + + ); }; const getSortingOrderColumn = (s: SortingOrder): string => { @@ -202,7 +204,7 @@ class ResourceScreenComponent extends React.Component { const theme = themeStyle(this.props.theme); const headerStyle = Object.assign({}, theme.headerStyle, { width: style.width }); - const rootStyle = { + const rootStyle:any = { ...style, overflowY: 'scroll', color: theme.color, @@ -212,34 +214,36 @@ class ResourceScreenComponent extends React.Component { rootStyle.height = style.height - 35; // Minus the header height delete rootStyle.width; - return
-
-
-
{ - _('This is an advanced tool to show the attachments that are linked to your notes. Please be careful when deleting one of them as they cannot be restored afterwards.') - }
- {this.state.isLoading &&
{_('Please wait...')}
} - {!this.state.isLoading &&
- {!this.state.resources &&
- {_('No resources!')} + return ( +
+
+
+
{ + _('This is an advanced tool to show the attachments that are linked to your notes. Please be careful when deleting one of them as they cannot be restored afterwards.') + }
+ {this.state.isLoading &&
{_('Please wait...')}
} + {!this.state.isLoading &&
+ {!this.state.resources &&
+ {_('No resources!')} +
+ } + {this.state.resources && this.state.resources.length === MAX_RESOURCES && +
{_('Warning: not all resources shown for performance reasons (limit: %s).', MAX_RESOURCES)}
+ } + {this.state.resources && this.onToggleSortOrder(order)} + onResourceClick={(resource) => this.openResource(resource)} + onResourceDelete={(resource) => this.onResourceDelete(resource)} + />}
} - {this.state.resources && this.state.resources.length === MAX_RESOURCES && -
{_('Warning: not all resources shown for performance reasons (limit: %s).', MAX_RESOURCES)}
- } - {this.state.resources && this.onToggleSortOrder(order)} - onResourceClick={(resource) => this.openResource(resource)} - onResourceDelete={(resource) => this.onResourceDelete(resource)} - />}
- }
-
; + ); } } diff --git a/ReactNativeClient/lib/components/note-body-viewer.js b/ReactNativeClient/lib/components/note-body-viewer.js index db5f19ebb9..79d185de59 100644 --- a/ReactNativeClient/lib/components/note-body-viewer.js +++ b/ReactNativeClient/lib/components/note-body-viewer.js @@ -21,11 +21,14 @@ class NoteBodyViewer extends Component { bodyHtml: '', }; + this.forceUpdate_ = false; + this.isMounted_ = false; this.markupToHtml_ = markupLanguageUtils.newMarkupToHtml(); this.reloadNote = this.reloadNote.bind(this); + this.watchFn = this.watchFn.bind(this); } componentDidMount() { @@ -38,6 +41,8 @@ class NoteBodyViewer extends Component { } async reloadNote() { + this.forceUpdate_ = false; + const note = this.props.note; const theme = themeStyle(this.props.theme); @@ -183,9 +188,18 @@ class NoteBodyViewer extends Component { } rebuildMd() { + this.forceUpdate_ = true; this.forceUpdate(); } + watchFn() { + // react-async will not fetch the data again after the first render + // so we use this watchFn function to force it to reload in certain + // cases. It is used in particular when re-rendering the note when + // a resource has been downloaded in auto mode. + return this.forceUpdate_; + } + render() { // Note: useWebKit={false} is needed to go around this bug: // https://github.com/react-native-community/react-native-webview/issues/376 @@ -206,7 +220,7 @@ class NoteBodyViewer extends Component { return ( - + {({ data, error, isPending }) => { if (error) { console.error(error);