From f8bcb569647c93b917651be4b22d4ac7d3a4a3d0 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 12 Nov 2017 18:12:05 +0000 Subject: [PATCH] Electron: update note in view when sync update note --- ElectronClient/app/gui/NoteText.jsx | 49 +++++++++++++++++------------ ElectronClient/app/gui/SideBar.jsx | 1 - ElectronClient/app/theme.js | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index a3a66dc0b..996dcf52b 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -105,29 +105,37 @@ class NoteTextComponent extends React.Component { }, 500); } + async reloadNote(props) { + this.mdToHtml_ = null; + + const noteId = props.noteId; + this.lastLoadedNoteId_ = noteId; + const note = noteId ? await Note.load(noteId) : null; + if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading + + // If we are loading nothing (noteId == null), make sure to + // set webviewReady to false too because the webview component + // is going to be removed in render(). + const webviewReady = this.webview_ && this.state.webviewReady && noteId; + + this.editorMaxScrollTop_ = 0; + + this.editorSetScrollTop(0); + + this.setState({ + note: note, + lastSavedNote: Object.assign({}, note), + webviewReady: webviewReady, + }); + } + async componentWillReceiveProps(nextProps) { if ('noteId' in nextProps && nextProps.noteId !== this.props.noteId) { - this.mdToHtml_ = null; + await this.reloadNote(nextProps); + } - const noteId = nextProps.noteId; - this.lastLoadedNoteId_ = noteId; - const note = noteId ? await Note.load(noteId) : null; - if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading - - // If we are loading nothing (noteId == null), make sure to - // set webviewReady to false too because the webview component - // is going to be removed in render(). - const webviewReady = this.webview_ && this.state.webviewReady && noteId; - - this.editorMaxScrollTop_ = 0; - - this.editorSetScrollTop(0); - - this.setState({ - note: note, - lastSavedNote: Object.assign({}, note), - webviewReady: webviewReady, - }); + if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) { + await this.reloadNote(nextProps); } } @@ -487,6 +495,7 @@ const mapStateToProps = (state) => { folders: state.folders, theme: state.settings.theme, showAdvancedOptions: state.settings.showAdvancedOptions, + syncStarted: state.syncStarted, }; }; diff --git a/ElectronClient/app/gui/SideBar.jsx b/ElectronClient/app/gui/SideBar.jsx index 2d74a3556..e2440d8b7 100644 --- a/ElectronClient/app/gui/SideBar.jsx +++ b/ElectronClient/app/gui/SideBar.jsx @@ -183,7 +183,6 @@ class SideBarComponent extends React.Component { } let lines = Synchronizer.reportToLines(this.props.syncReport); - console.info(lines); const syncReportText = []; for (let i = 0; i < lines.length; i++) { syncReportText.push(
{lines[i]}
); diff --git a/ElectronClient/app/theme.js b/ElectronClient/app/theme.js index ead96b523..ca70775d1 100644 --- a/ElectronClient/app/theme.js +++ b/ElectronClient/app/theme.js @@ -33,7 +33,7 @@ const globalStyle = { }; // For WebView - must correspond to the properties above -globalStyle.htmlFontSize =globalStyle.fontSize + 'px'; +globalStyle.htmlFontSize = globalStyle.fontSize + 'px'; globalStyle.htmlColor ='black'; // Note: CSS in WebView component only supports named colors or rgb() notation globalStyle.htmlBackgroundColor ='white'; globalStyle.htmlDividerColor ='Gainsboro';