mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-14 18:27:44 +02:00
Auto save note
This commit is contained in:
parent
8bf85b6b88
commit
5a7fde7d21
@ -28,6 +28,7 @@ class NoteTextComponent extends React.Component {
|
||||
|
||||
this.webviewListeners_ = null;
|
||||
this.ignoreNextEditorScroll_ = false;
|
||||
this.scheduleSaveTimeout_ = null;
|
||||
}
|
||||
|
||||
mdToHtml() {
|
||||
@ -37,18 +38,32 @@ class NoteTextComponent extends React.Component {
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
|
||||
|
||||
await shared.initState(this);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.saveIfNeeded();
|
||||
|
||||
this.mdToHtml_ = null;
|
||||
this.destroyWebview();
|
||||
}
|
||||
|
||||
async saveIfNeeded() {
|
||||
if (this.scheduleSaveTimeout_) clearTimeout(this.scheduleSaveTimeout_);
|
||||
this.scheduleSaveTimeout_ = null;
|
||||
if (!shared.isModified(this)) return;
|
||||
await shared.saveNoteButton_press(this);
|
||||
}
|
||||
|
||||
scheduleSave() {
|
||||
if (this.scheduleSaveTimeout_) clearTimeout(this.scheduleSaveTimeout_);
|
||||
this.scheduleSaveTimeout_ = setTimeout(() => {
|
||||
this.saveIfNeeded();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
async componentWillReceiveProps(nextProps) {
|
||||
if ('noteId' in nextProps) {
|
||||
if ('noteId' in nextProps && nextProps.noteId !== this.props.noteId) {
|
||||
this.mdToHtml_ = null;
|
||||
|
||||
const noteId = nextProps.noteId;
|
||||
@ -73,23 +88,17 @@ class NoteTextComponent extends React.Component {
|
||||
|
||||
title_changeText(text) {
|
||||
shared.noteComponent_change(this, 'title', text);
|
||||
this.scheduleSave();
|
||||
}
|
||||
|
||||
body_changeText(text) {
|
||||
shared.noteComponent_change(this, 'body', text);
|
||||
//this.updateScrollHeight();
|
||||
}
|
||||
|
||||
async saveNoteButton_press() {
|
||||
await shared.saveNoteButton_press(this);
|
||||
}
|
||||
|
||||
async saveOneProperty(name, value) {
|
||||
await shared.saveOneProperty(this, name, value);
|
||||
editor_change(event) {
|
||||
shared.noteComponent_change(this, 'body', event.target.value);
|
||||
this.scheduleSave();
|
||||
}
|
||||
|
||||
toggleIsTodo_onPress() {
|
||||
shared.toggleIsTodo_onPress(this);
|
||||
this.scheduleSave();
|
||||
}
|
||||
|
||||
showMetadata_onPress() {
|
||||
@ -210,8 +219,6 @@ class NoteTextComponent extends React.Component {
|
||||
const note = this.state.note;
|
||||
const body = note ? note.body : '';
|
||||
|
||||
console.info(this.state.scrollHeight);
|
||||
|
||||
const viewerStyle = {
|
||||
width: Math.floor(style.width / 2),
|
||||
height: style.height,
|
||||
@ -240,7 +247,7 @@ class NoteTextComponent extends React.Component {
|
||||
}
|
||||
|
||||
const viewer = <webview style={viewerStyle} nodeintegration="1" src="note-content.html" ref={(elem) => { this.webview_ref(elem); } } />
|
||||
const editor = <textarea style={editorStyle} value={body} onScroll={() => { this.editor_scroll(); }} onChange={(text) => { this.body_changeText(text) }} ref={(elem) => { this.editor_ref(elem); } }></textarea>
|
||||
const editor = <textarea style={editorStyle} value={body} onScroll={() => { this.editor_scroll(); }} onChange={(event) => { this.editor_change(event) }} ref={(elem) => { this.editor_ref(elem); } }></textarea>
|
||||
|
||||
return (
|
||||
<div style={style}>
|
||||
|
Loading…
Reference in New Issue
Block a user