| author | Alexandre Segura <mex.zktk@gmail.com> |
| Fri, 09 Jun 2017 15:24:53 +0200 | |
| changeset 26 | 930e486ad0a8 |
| parent 21 | 284e866f55c7 |
| child 29 | 4cfeabef7d5e |
| 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(); |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
29 |
const categories = this.refs.editor.asCategories(); |
| 15 | 30 |
|
31 |
this.props.addNote(this.props.session, { |
|
32 |
plain: plain, |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
33 |
raw: raw, |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
34 |
html: html, |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
35 |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
36 |
startedAt: this.state.startedAt, |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
37 |
finishedAt: moment().format('H:mm:ss'), |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
38 |
categories: categories, |
| 15 | 39 |
}); |
40 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
41 |
this.refs.editor.clear(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
42 |
setTimeout(() => this.refs.editor.focus(), 250); |
| 1 | 43 |
} |
44 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
45 |
componentDidMount() { |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
46 |
const text = this.refs.editor.asPlain(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
47 |
this.setState({ buttonDisabled: text.length === 0 }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
48 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
49 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
50 |
renderTiming() { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
51 |
if (this.state.startedAt && this.state.finishedAt) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
52 |
return ( |
|
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 |
<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
|
55 |
</span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
56 |
) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
57 |
} else { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
58 |
return ( |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
59 |
<span>No timing</span> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
60 |
) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
61 |
} |
| 1 | 62 |
} |
63 |
||
64 |
render() { |
|
65 |
return ( |
|
| 2 | 66 |
<Form> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
67 |
<Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
68 |
<Col md={6}> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
69 |
{ this.renderTiming() } |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
70 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
71 |
<Col md={6} className="text-right"> |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
72 |
<Clock /> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
73 |
</Col> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
74 |
</Row> |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
75 |
<hr /> |
| 2 | 76 |
<FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
77 |
<div className="editor-wrapper"> |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
78 |
<SlateEditor ref="editor" onChange={this.onEditorChange} /> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
79 |
</div> |
| 2 | 80 |
</FormGroup> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
81 |
<Button disabled={this.state.buttonDisabled} bsStyle="primary" type="button" onClick={this.onAddNoteClick}>Add Note</Button> |
| 2 | 82 |
</Form> |
| 1 | 83 |
); |
84 |
} |
|
85 |
} |
|
86 |
||
87 |
NoteInput.propTypes = { |
|
88 |
addNote: PropTypes.func.isRequired |
|
89 |
}; |
|
90 |
||
91 |
export default NoteInput; |