mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Saving/loading notes from Electron
This commit is contained in:
parent
3de7534d1d
commit
100b98bff8
@ -5,7 +5,7 @@ const { connect } = require('react-redux');
|
|||||||
class NoteListComponent extends React.Component {
|
class NoteListComponent extends React.Component {
|
||||||
|
|
||||||
itemRenderer(index, item) {
|
itemRenderer(index, item) {
|
||||||
const onClick = () => {
|
const onClick = (item) => {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'NOTES_SELECT',
|
type: 'NOTES_SELECT',
|
||||||
noteId: item.id,
|
noteId: item.id,
|
||||||
@ -14,7 +14,7 @@ class NoteListComponent extends React.Component {
|
|||||||
|
|
||||||
let classes = ['item'];
|
let classes = ['item'];
|
||||||
classes.push(index % 2 === 0 ? 'even' : 'odd');
|
classes.push(index % 2 === 0 ? 'even' : 'odd');
|
||||||
return <div onClick={() => { onClick() }} className={classes.join(' ')} key={index}>{item.title}</div>
|
return <div onClick={() => { onClick(item) }} className={classes.join(' ')} key={index}>{item.title + ' ' + item.id.substr(0,4)}</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
const { Note } = require('lib/models/note.js');
|
||||||
const { connect } = require('react-redux');
|
const { connect } = require('react-redux');
|
||||||
const { MdToHtml } = require('lib/markdown-utils.js');
|
const { MdToHtml } = require('lib/markdown-utils.js');
|
||||||
|
const shared = require('lib/components/shared/note-screen-shared.js');
|
||||||
|
|
||||||
class NoteTextComponent extends React.Component {
|
class NoteTextComponent extends React.Component {
|
||||||
|
|
||||||
componentWillMount() {
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
note: Note.new(),
|
||||||
|
mode: 'view',
|
||||||
|
noteMetadata: '',
|
||||||
|
showNoteMetadata: false,
|
||||||
|
folder: null,
|
||||||
|
lastSavedNote: null,
|
||||||
|
isLoading: true,
|
||||||
|
webviewReady: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount() {
|
||||||
this.mdToHtml_ = new MdToHtml();
|
this.mdToHtml_ = new MdToHtml();
|
||||||
|
|
||||||
this.setState({
|
await shared.initState(this);
|
||||||
note: null,
|
|
||||||
webviewReady: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -23,7 +37,39 @@ class NoteTextComponent extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.noteId) this.reloadNote();
|
if (nextProps.noteId) this.reloadNote(nextProps.noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
isModified() {
|
||||||
|
return shared.isModified(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshNoteMetadata(force = null) {
|
||||||
|
return shared.refreshNoteMetadata(this, force);
|
||||||
|
}
|
||||||
|
|
||||||
|
title_changeText(text) {
|
||||||
|
shared.noteComponent_change(this, 'title', text);
|
||||||
|
}
|
||||||
|
|
||||||
|
body_changeText(text) {
|
||||||
|
shared.noteComponent_change(this, 'body', text);
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveNoteButton_press() {
|
||||||
|
await shared.saveNoteButton_press(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveOneProperty(name, value) {
|
||||||
|
await shared.saveOneProperty(this, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleIsTodo_onPress() {
|
||||||
|
shared.toggleIsTodo_onPress(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
showMetadata_onPress() {
|
||||||
|
shared.showMetadata_onPress(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
webview_domReady() {
|
webview_domReady() {
|
||||||
@ -31,21 +77,23 @@ class NoteTextComponent extends React.Component {
|
|||||||
webviewReady: true,
|
webviewReady: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.webview_.openDevTools();
|
// this.webview_.openDevTools();
|
||||||
|
|
||||||
this.webview_.addEventListener('ipc-message', (event) => {
|
this.webview_.addEventListener('ipc-message', (event) => {
|
||||||
const msg = event.channel;
|
const msg = event.channel;
|
||||||
|
|
||||||
if (msg.indexOf('checkboxclick:') === 0) {
|
if (msg.indexOf('checkboxclick:') === 0) {
|
||||||
const newBody = this.mdToHtml_.handleCheckboxClick(msg, this.state.note.body);
|
const newBody = this.mdToHtml_.handleCheckboxClick(msg, this.state.note.body);
|
||||||
// this.saveOneProperty('body', newBody);
|
this.saveOneProperty('body', newBody);
|
||||||
//if (onCheckboxChange) onCheckboxChange(newBody);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadNote() {
|
async reloadNote(noteId) {
|
||||||
const note = this.props.noteId ? await Note.load(this.props.noteId) : null;
|
const note = noteId ? await Note.load(noteId) : null;
|
||||||
|
|
||||||
|
console.info('Reload note: ' + noteId, note);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
note: note,
|
note: note,
|
||||||
});
|
});
|
||||||
@ -55,6 +103,8 @@ class NoteTextComponent extends React.Component {
|
|||||||
const note = this.state.note;
|
const note = this.state.note;
|
||||||
const body = note ? note.body : 'no note';
|
const body = note ? note.body : 'no note';
|
||||||
|
|
||||||
|
console.info('NOTE: ' + (note ? note.title + ' ' + note.id : 'UNDEFINED'));
|
||||||
|
|
||||||
if (this.state.webviewReady) {
|
if (this.state.webviewReady) {
|
||||||
const mdOptions = {
|
const mdOptions = {
|
||||||
onResourceLoaded: () => {
|
onResourceLoaded: () => {
|
||||||
@ -86,6 +136,11 @@ const mapStateToProps = (state) => {
|
|||||||
return {
|
return {
|
||||||
noteId: state.selectedNoteId,
|
noteId: state.selectedNoteId,
|
||||||
notes: state.notes,
|
notes: state.notes,
|
||||||
|
folderId: state.selectedFolderId,
|
||||||
|
itemType: state.selectedItemType,
|
||||||
|
folders: state.folders,
|
||||||
|
theme: state.settings.theme,
|
||||||
|
showAdvancedOptions: state.settings.showAdvancedOptions,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
folder: null,
|
folder: null,
|
||||||
lastSavedNote: null,
|
lastSavedNote: null,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
resources: {},
|
|
||||||
titleTextInputHeight: 20,
|
titleTextInputHeight: 20,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -137,7 +136,11 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
|
|
||||||
await shared.initState(this);
|
await shared.initState(this);
|
||||||
|
|
||||||
shared.refreshNoteMetadata(this);
|
this.refreshNoteMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshNoteMetadata(force = null) {
|
||||||
|
return shared.refreshNoteMetadata(this, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -40,7 +40,7 @@ shared.saveNoteButton_press = async function(comp) {
|
|||||||
note: note,
|
note: note,
|
||||||
});
|
});
|
||||||
if (isNew) Note.updateGeolocation(note.id);
|
if (isNew) Note.updateGeolocation(note.id);
|
||||||
shared.refreshNoteMetadata(comp);
|
comp.refreshNoteMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.saveOneProperty = async function(comp, name, value) {
|
shared.saveOneProperty = async function(comp, name, value) {
|
||||||
@ -111,7 +111,7 @@ shared.initState = async function(comp) {
|
|||||||
|
|
||||||
shared.showMetadata_onPress = function(comp) {
|
shared.showMetadata_onPress = function(comp) {
|
||||||
comp.setState({ showNoteMetadata: !comp.state.showNoteMetadata });
|
comp.setState({ showNoteMetadata: !comp.state.showNoteMetadata });
|
||||||
shared.refreshNoteMetadata(comp, true);
|
comp.refreshNoteMetadata(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.toggleIsTodo_onPress = function(comp) {
|
shared.toggleIsTodo_onPress = function(comp) {
|
||||||
|
Loading…
Reference in New Issue
Block a user