1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ElectronClient/app/gui/NoteText.jsx

47 lines
852 B
React
Raw Normal View History

2017-11-05 01:27:13 +02:00
//const { BaseModel } = require('lib/base-model.js');
const React = require('react');
const { connect } = require('react-redux');
2017-11-05 01:27:13 +02:00
class NoteTextComponent extends React.Component {
componentWillMount() {
this.setState({
note: null,
});
}
componentWillReceiveProps(nextProps) {
if (nextProps.noteId) this.reloadNote();
}
async reloadNote() {
const note = this.props.noteId ? await Note.load(this.props.noteId) : null;
this.setState({
note: note,
});
}
render() {
const note = this.state.note;
const body = note ? note.body : 'no note';
return (
<div style={this.props.style}>
{ body }
</div>
);
}
}
const mapStateToProps = (state) => {
return {
noteId: state.selectedNoteId,
notes: state.notes,
};
};
const NoteText = connect(mapStateToProps)(NoteTextComponent);
module.exports = { NoteText };