diff --git a/src/components/formItem/index.js b/src/components/formItem/index.js
index cfa222a..c680322 100644
--- a/src/components/formItem/index.js
+++ b/src/components/formItem/index.js
@@ -5,23 +5,39 @@ import RemoveButton from '../../components/removeButton/';
import style from './style';
export default class FormItem extends Component {
+ constructor() {
+ super();
+
+ this.handleChange = this.handleChange.bind(this);
+ this.removeField = this.removeField.bind(this);
+ }
+
+ handleChange(e, kind) {
+ this.props.handleState(kind, e.target.value);
+ }
+
+ removeField(kind) {
+ this.props.handleState(kind, null);
+ }
+
render() {
return (
-
);
}
@@ -30,4 +46,5 @@ export default class FormItem extends Component {
FormItem.propTypes = {
item: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
+ handleState: PropTypes.func.isRequired,
};
diff --git a/src/routes/edit/index.js b/src/routes/edit/index.js
index f9a267c..9d10cbe 100644
--- a/src/routes/edit/index.js
+++ b/src/routes/edit/index.js
@@ -20,6 +20,8 @@ export default class Edit extends Component {
this.handleSave = this.handleSave.bind(this);
this.handleResetLoc = this.handleResetLoc.bind(this);
+ this.handleState = this.handleState.bind(this);
+ this.handleChange = this.handleChange.bind(this);
this.handleEditSave = this.handleEditSave.bind(this);
this.state = {
@@ -29,9 +31,13 @@ export default class Edit extends Component {
}
componentWillMount(nextProps) {
- this.ref = base.bindToState(`/${this.props.uid}/mes/${this.props.measurementId}`, {
+ this.ref = base.fetch(`/${this.props.uid}/mes/${this.props.measurementId}`, {
context: this,
- state: 'measurement',
+ then(data) {
+ this.setState({
+ measurement: data,
+ });
+ },
});
}
@@ -52,6 +58,18 @@ export default class Edit extends Component {
});
}
+ handleState(kind, value) {
+ const measurement = { ...this.state.measurement };
+ measurement[kind] = value;
+ this.setState({
+ measurement,
+ });
+ }
+
+ handleChange(e, kind) {
+ this.handleState(kind, e.target.value);
+ }
+
handleSave() {
this.setState({
open: false,
@@ -59,7 +77,13 @@ export default class Edit extends Component {
}
handleEditSave() {
- route(`/mes/${this.props.measurementId}`);
+ const measurementId = this.props.measurementId;
+ base.update(`/${this.props.uid}/mes/${this.props.measurementId}`, {
+ data: this.state.measurement,
+ then() {
+ route(`/mes/${measurementId}`);
+ },
+ });
}
render() {
@@ -101,9 +125,19 @@ export default class Edit extends Component {