1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Electron: update note in view when sync update note

This commit is contained in:
Laurent Cozic 2017-11-12 18:12:05 +00:00
parent 26d1c0d79d
commit f8bcb56964
3 changed files with 30 additions and 22 deletions

View File

@ -105,29 +105,37 @@ class NoteTextComponent extends React.Component {
}, 500); }, 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) { async componentWillReceiveProps(nextProps) {
if ('noteId' in nextProps && nextProps.noteId !== this.props.noteId) { if ('noteId' in nextProps && nextProps.noteId !== this.props.noteId) {
this.mdToHtml_ = null; await this.reloadNote(nextProps);
}
const noteId = nextProps.noteId; if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) {
this.lastLoadedNoteId_ = noteId; await this.reloadNote(nextProps);
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,
});
} }
} }
@ -487,6 +495,7 @@ const mapStateToProps = (state) => {
folders: state.folders, folders: state.folders,
theme: state.settings.theme, theme: state.settings.theme,
showAdvancedOptions: state.settings.showAdvancedOptions, showAdvancedOptions: state.settings.showAdvancedOptions,
syncStarted: state.syncStarted,
}; };
}; };

View File

@ -183,7 +183,6 @@ class SideBarComponent extends React.Component {
} }
let lines = Synchronizer.reportToLines(this.props.syncReport); let lines = Synchronizer.reportToLines(this.props.syncReport);
console.info(lines);
const syncReportText = []; const syncReportText = [];
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
syncReportText.push(<div key={i}>{lines[i]}</div>); syncReportText.push(<div key={i}>{lines[i]}</div>);

View File

@ -33,7 +33,7 @@ const globalStyle = {
}; };
// For WebView - must correspond to the properties above // 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.htmlColor ='black'; // Note: CSS in WebView component only supports named colors or rgb() notation
globalStyle.htmlBackgroundColor ='white'; globalStyle.htmlBackgroundColor ='white';
globalStyle.htmlDividerColor ='Gainsboro'; globalStyle.htmlDividerColor ='Gainsboro';