diff --git a/lib/app.jsx b/lib/app.jsx index 6fb0ca6b9..b9e8dfbd7 100644 --- a/lib/app.jsx +++ b/lib/app.jsx @@ -320,12 +320,28 @@ export const App = connect( }); }; - onUpdateContent = (note, content) => - this.props.actions.updateNoteContent({ - noteBucket: this.props.noteBucket, - note, - content, - }); + onUpdateContent = (note, content) => { + if (!note) { + return; + } + + const updatedNote = { + ...note, + data: { + ...note.data, + content, + modificationDate: Math.floor(Date.now() / 1000), + }, + }; + + // update the bucket but don't force sync right away + // as this happens per keystroke when the user is editing + // a note. The NoteEditor will notify via props when + // it's time to sync via Simperium + const { noteBucket } = this.props; + + noteBucket.update(note.id, updatedNote.data, {}, { sync: false }); + }; syncNote = noteId => { this.props.noteBucket.touch(noteId); diff --git a/lib/flux/app-state.js b/lib/flux/app-state.js index 76218d4d0..39377d95b 100644 --- a/lib/flux/app-state.js +++ b/lib/flux/app-state.js @@ -404,8 +404,6 @@ export const actionMap = new ActionMap({ return; } - state.note.data = data; - dispatch( this.action('loadAndSelectNote', { noteBucket, @@ -439,28 +437,6 @@ export const actionMap = new ActionMap({ }, }, - updateNoteContent: { - creator({ noteBucket, note, content }) { - return (dispatch, getState) => { - if (note) { - note.data.content = content; - note.data.modificationDate = Math.floor(Date.now() / 1000); - - // update the bucket don't sync right away - // as this happens per keystroke when the user is editing - // a note. The NoteEditor notify via props when its time - // to sync via Simperium - noteBucket.update(note.id, note.data, {}, { sync: false }); - - // Check if note is still selected (to avoid race conditions) - if (get(getState().appState, 'note.id') === note.id) { - dispatch(this.action('selectNote', { note })); - } - } - }; - }, - }, - trashNote: { creator({ noteBucket, note, previousIndex }) { return dispatch => { diff --git a/lib/note-detail/index.jsx b/lib/note-detail/index.jsx index dc1f01ae8..f5ba5a9ec 100644 --- a/lib/note-detail/index.jsx +++ b/lib/note-detail/index.jsx @@ -33,7 +33,6 @@ export class NoteDetail extends Component { spellCheckEnabled: PropTypes.bool.isRequired, storeFocusEditor: PropTypes.func, storeHasFocus: PropTypes.func, - updateNoteContent: PropTypes.func.isRequired, }; static defaultProps = { @@ -130,6 +129,8 @@ export class NoteDetail extends Component { hasFocus = () => this.editorHasFocus && this.editorHasFocus(); onPreviewClick = event => { + const { note, onChangeContent, syncNote } = this.props; + for (let node = event.target; node !== null; node = node.parentNode) { // open markdown preview links in a new window if (node.tagName === 'A') { @@ -137,18 +138,16 @@ export class NoteDetail extends Component { viewExternalUrl(node.href); break; } + // handle task list items if (node.className === 'task-list-item') { event.preventDefault(); - const { note, noteBucket, updateNoteContent } = this.props; - toggleTask({ - taskNode: node, - text: note.data.content, - }) - .then(newNoteContent => { - updateNoteContent({ noteBucket, note, content: newNoteContent }); - }) - .catch(console.log); + toggleTask({ taskNode: node, text: note.data.content }).then( + newContent => { + onChangeContent(note, newContent); + syncNote(note.id); + } + ); break; } } @@ -258,11 +257,10 @@ const mapStateToProps = ({ appState: state, settings }) => ({ spellCheckEnabled: settings.spellCheckEnabled, }); -const { setShouldPrintNote, updateNoteContent } = appState.actionCreators; +const { setShouldPrintNote } = appState.actionCreators; const mapDispatchToProps = { onNotePrinted: () => setShouldPrintNote({ shouldPrint: false }), - updateNoteContent, }; export default connect(