| author | Alexandre Segura <mex.zktk@gmail.com> |
| Thu, 08 Jun 2017 11:13:41 +0200 | |
| changeset 21 | 284e866f55c7 |
| parent 17 | 877d8796b86d |
| child 26 | 930e486ad0a8 |
| 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'; |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
7 |
import Clock from './Clock' |
| 1 | 8 |
|
9 |
class NoteInput extends Component { |
|
10 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
11 |
state = { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
12 |
buttonDisabled: false, |
|
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 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
47 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
48 |
renderTiming() { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
49 |
if (this.state.startedAt && this.state.finishedAt) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
50 |
return ( |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
51 |
<span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
52 |
<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
|
53 |
</span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
54 |
) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
55 |
} else { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
56 |
return ( |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
57 |
<span>No timing</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 |
} |
| 1 | 60 |
} |
61 |
||
62 |
render() { |
|
63 |
return ( |
|
| 2 | 64 |
<Form> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
65 |
<Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
66 |
<Col md={6}> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
67 |
{ this.renderTiming() } |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
68 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
69 |
<Col md={6} className="text-right"> |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
70 |
<Clock /> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
71 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
72 |
</Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
73 |
<hr /> |
| 2 | 74 |
<FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
75 |
<div className="editor-wrapper"> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
76 |
<SlateEditor ref="editor" onChange={this.onEditorChange} /> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
77 |
</div> |
| 2 | 78 |
</FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
79 |
<Button disabled={this.state.buttonDisabled} bsStyle="primary" type="button" onClick={this.onAddNoteClick}>Add Note</Button> |
| 2 | 80 |
</Form> |
| 1 | 81 |
); |
82 |
} |
|
83 |
} |
|
84 |
||
85 |
NoteInput.propTypes = { |
|
86 |
addNote: PropTypes.func.isRequired |
|
87 |
}; |
|
88 |
||
89 |
export default NoteInput; |