2017-11-05 01:27:13 +02:00
|
|
|
//const { BaseModel } = require('lib/base-model.js');
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
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 };
|