1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ReactNativeClient/src/components/screens/note.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-05-12 22:23:54 +02:00
import React, { Component } from 'react';
import { View, Button, TextInput } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'src/log.js'
import { Note } from 'src/models/note.js'
2017-05-16 21:57:09 +02:00
import { ScreenHeader } from 'src/components/screen-header.js';
2017-05-12 22:23:54 +02:00
class NoteScreenComponent extends React.Component {
2017-05-16 21:57:09 +02:00
static navigationOptions = (options) => {
return { header: null };
}
2017-05-12 22:23:54 +02:00
constructor() {
super();
2017-05-20 00:16:50 +02:00
this.state = { note: Note.new() }
2017-05-12 22:23:54 +02:00
}
componentWillMount() {
this.setState({ note: this.props.note });
}
noteComponent_change = (propName, propValue) => {
this.setState((prevState, props) => {
let note = Object.assign({}, prevState.note);
note[propName] = propValue;
return { note: note }
});
}
title_changeText = (text) => {
this.noteComponent_change('title', text);
}
body_changeText = (text) => {
this.noteComponent_change('body', text);
}
saveNoteButton_press = () => {
Note.save(this.state.note).then((note) => {
this.props.dispatch({
type: 'NOTES_UPDATE_ONE',
note: note,
});
}).catch((error) => {
Log.warn('Cannot save note', error);
});
}
render() {
return (
<View style={{flex: 1}}>
2017-05-16 21:57:09 +02:00
<ScreenHeader navState={this.props.navigation.state} />
2017-05-12 22:23:54 +02:00
<TextInput value={this.state.note.title} onChangeText={this.title_changeText} />
<TextInput style={{flex: 1, textAlignVertical: 'top'}} multiline={true} value={this.state.note.body} onChangeText={this.body_changeText} />
<Button title="Save note" onPress={this.saveNoteButton_press} />
</View>
);
}
}
const NoteScreen = connect(
(state) => {
return {
2017-05-20 00:16:50 +02:00
note: state.selectedNoteId ? Note.byId(state.notes, state.selectedNoteId) : Note.new(state.selectedFolderId),
2017-05-12 22:23:54 +02:00
};
}
)(NoteScreenComponent)
export { NoteScreen };