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 {
|
||||
|
||||
itemRenderer(index, item) {
|
||||
const onClick = () => {
|
||||
const onClick = (item) => {
|
||||
this.props.dispatch({
|
||||
type: 'NOTES_SELECT',
|
||||
noteId: item.id,
|
||||
@ -14,7 +14,7 @@ class NoteListComponent extends React.Component {
|
||||
|
||||
let classes = ['item'];
|
||||
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() {
|
||||
|
@ -1,16 +1,30 @@
|
||||
const React = require('react');
|
||||
const { Note } = require('lib/models/note.js');
|
||||
const { connect } = require('react-redux');
|
||||
const { MdToHtml } = require('lib/markdown-utils.js');
|
||||
const shared = require('lib/components/shared/note-screen-shared.js');
|
||||
|
||||
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.setState({
|
||||
note: null,
|
||||
webviewReady: false,
|
||||
});
|
||||
await shared.initState(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -23,7 +37,39 @@ class NoteTextComponent extends React.Component {
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -31,21 +77,23 @@ class NoteTextComponent extends React.Component {
|
||||
webviewReady: true,
|
||||
});
|
||||
|
||||
this.webview_.openDevTools();
|
||||
// this.webview_.openDevTools();
|
||||
|
||||
this.webview_.addEventListener('ipc-message', (event) => {
|
||||
const msg = event.channel;
|
||||
|
||||
if (msg.indexOf('checkboxclick:') === 0) {
|
||||
const newBody = this.mdToHtml_.handleCheckboxClick(msg, this.state.note.body);
|
||||
// this.saveOneProperty('body', newBody);
|
||||
//if (onCheckboxChange) onCheckboxChange(newBody);
|
||||
this.saveOneProperty('body', newBody);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async reloadNote() {
|
||||
const note = this.props.noteId ? await Note.load(this.props.noteId) : null;
|
||||
async reloadNote(noteId) {
|
||||
const note = noteId ? await Note.load(noteId) : null;
|
||||
|
||||
console.info('Reload note: ' + noteId, note);
|
||||
|
||||
this.setState({
|
||||
note: note,
|
||||
});
|
||||
@ -55,6 +103,8 @@ class NoteTextComponent extends React.Component {
|
||||
const note = this.state.note;
|
||||
const body = note ? note.body : 'no note';
|
||||
|
||||
console.info('NOTE: ' + (note ? note.title + ' ' + note.id : 'UNDEFINED'));
|
||||
|
||||
if (this.state.webviewReady) {
|
||||
const mdOptions = {
|
||||
onResourceLoaded: () => {
|
||||
@ -86,6 +136,11 @@ const mapStateToProps = (state) => {
|
||||
return {
|
||||
noteId: state.selectedNoteId,
|
||||
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,
|
||||
lastSavedNote: null,
|
||||
isLoading: true,
|
||||
resources: {},
|
||||
titleTextInputHeight: 20,
|
||||
};
|
||||
|
||||
@ -137,7 +136,11 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
|
||||
await shared.initState(this);
|
||||
|
||||
shared.refreshNoteMetadata(this);
|
||||
this.refreshNoteMetadata();
|
||||
}
|
||||
|
||||
refreshNoteMetadata(force = null) {
|
||||
return shared.refreshNoteMetadata(this, force);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -40,7 +40,7 @@ shared.saveNoteButton_press = async function(comp) {
|
||||
note: note,
|
||||
});
|
||||
if (isNew) Note.updateGeolocation(note.id);
|
||||
shared.refreshNoteMetadata(comp);
|
||||
comp.refreshNoteMetadata();
|
||||
}
|
||||
|
||||
shared.saveOneProperty = async function(comp, name, value) {
|
||||
@ -111,7 +111,7 @@ shared.initState = async function(comp) {
|
||||
|
||||
shared.showMetadata_onPress = function(comp) {
|
||||
comp.setState({ showNoteMetadata: !comp.state.showNoteMetadata });
|
||||
shared.refreshNoteMetadata(comp, true);
|
||||
comp.refreshNoteMetadata(true);
|
||||
}
|
||||
|
||||
shared.toggleIsTodo_onPress = function(comp) {
|
||||
|
Loading…
Reference in New Issue
Block a user