| author | Alexandre Segura <mex.zktk@gmail.com> |
| Thu, 01 Jun 2017 18:46:34 +0200 | |
| changeset 17 | 877d8796b86d |
| parent 16 | e67cd18cc594 |
| child 21 | 284e866f55c7 |
| permissions | -rw-r--r-- |
| 1 | 1 |
import React, {Component} from 'react'; |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
2 |
import { Form, FormGroup, Button, Label, Row, Col } from 'react-bootstrap'; |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
3 |
import moment from 'moment'; |
| 2 | 4 |
|
| 1 | 5 |
import PropTypes from 'prop-types'; |
| 5 | 6 |
import SlateEditor from './SlateEditor'; |
| 1 | 7 |
|
8 |
class NoteInput extends Component { |
|
9 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
10 |
state = { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
11 |
buttonDisabled: false, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
12 |
time: moment().format('H:mm:ss'), |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
13 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
14 |
finishedAt: null, |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
15 |
} |
| 1 | 16 |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
17 |
onEditorChange = (e) => { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
18 |
this.setState({ |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
19 |
buttonDisabled: e.state.document.length === 0, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
20 |
startedAt: e.startedAt, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
21 |
finishedAt: e.finishedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
22 |
}); |
| 1 | 23 |
} |
24 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
25 |
onAddNoteClick = () => { |
| 15 | 26 |
const plain = this.refs.editor.asPlain(); |
27 |
const raw = this.refs.editor.asRaw(); |
|
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
28 |
const html = this.refs.editor.asHtml(); |
| 15 | 29 |
|
30 |
this.props.addNote(this.props.session, { |
|
31 |
plain: plain, |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
32 |
raw: raw, |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
33 |
html: html, |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
34 |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
35 |
startedAt: this.state.startedAt, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
36 |
finishedAt: moment().format('H:mm:ss') |
| 15 | 37 |
}); |
38 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
39 |
this.refs.editor.clear(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
40 |
setTimeout(() => this.refs.editor.focus(), 250); |
| 1 | 41 |
} |
42 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
43 |
componentDidMount() { |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
44 |
const text = this.refs.editor.asPlain(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
45 |
this.setState({ buttonDisabled: text.length === 0 }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
46 |
setInterval(() => { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
47 |
const time = moment().format('H:mm:ss'); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
48 |
this.setState({ time }); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
49 |
}, 1000); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
50 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
51 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
52 |
renderTiming() { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
53 |
if (this.state.startedAt && this.state.finishedAt) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
54 |
return ( |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
55 |
<span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
56 |
<Label>{this.state.startedAt}</Label> ⇒ <Label>{this.state.finishedAt}</Label> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
57 |
</span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
58 |
) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
59 |
} else { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
60 |
return ( |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
61 |
<span>No timing</span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
62 |
) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
63 |
} |
| 1 | 64 |
} |
65 |
||
66 |
render() { |
|
67 |
return ( |
|
| 2 | 68 |
<Form> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
69 |
<Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
70 |
<Col md={6}> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
71 |
{ this.renderTiming() } |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
72 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
73 |
<Col md={6} className="text-right"> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
74 |
<Label bsStyle="info">{ this.state.time }</Label> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
75 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
76 |
</Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
77 |
<hr /> |
| 2 | 78 |
<FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
79 |
<div className="editor-wrapper"> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
80 |
<SlateEditor ref="editor" onChange={this.onEditorChange} /> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
81 |
</div> |
| 2 | 82 |
</FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
83 |
<Button disabled={this.state.buttonDisabled} bsStyle="primary" type="button" onClick={this.onAddNoteClick}>Add Note</Button> |
| 2 | 84 |
</Form> |
| 1 | 85 |
); |
86 |
} |
|
87 |
} |
|
88 |
||
89 |
NoteInput.propTypes = { |
|
90 |
addNote: PropTypes.func.isRequired |
|
91 |
}; |
|
92 |
||
93 |
export default NoteInput; |