| author | ymh <ymh.work@gmail.com> |
| Sun, 30 Jul 2017 01:02:09 +0200 | |
| changeset 130 | 78246db1cbac |
| parent 125 | c653f49fabfb |
| child 138 | a1fb2ced3049 |
| permissions | -rw-r--r-- |
|
29
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
26
diff
changeset
|
1 |
import React, { Component } from 'react'; |
| 77 | 2 |
import { Form, FormControl } from 'react-bootstrap'; |
| 2 | 3 |
|
| 1 | 4 |
import PropTypes from 'prop-types'; |
| 5 | 5 |
import SlateEditor from './SlateEditor'; |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
6 |
import { now } from '../utils'; |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
7 |
|
| 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 = () => { |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
26 |
|
| 15 | 27 |
const plain = this.refs.editor.asPlain(); |
28 |
const raw = this.refs.editor.asRaw(); |
|
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
29 |
const html = this.refs.editor.asHtml(); |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
30 |
const categories = this.refs.editor.asCategories(); |
| 78 | 31 |
const marginComment = this.marginComment.value; |
| 15 | 32 |
|
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
33 |
this.props.addNote(this.props.session, { |
| 15 | 34 |
plain: plain, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
35 |
raw: raw, |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
36 |
html: html, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
37 |
startedAt: this.state.startedAt, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
38 |
finishedAt: now(), |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
39 |
categories: categories, |
| 78 | 40 |
marginComment: marginComment, |
| 15 | 41 |
}); |
42 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
43 |
this.refs.editor.clear(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
44 |
setTimeout(() => this.refs.editor.focus(), 250); |
| 1 | 45 |
} |
46 |
||
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
47 |
onCheckboxChange = (e) => { |
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
48 |
this.props.setAutoSubmit(e.target.checked); |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
49 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
50 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
51 |
componentDidMount() { |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
52 |
const text = this.refs.editor.asPlain(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
53 |
this.setState({ buttonDisabled: text.length === 0 }); |
|
16
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 |
|
| 1 | 56 |
render() { |
57 |
return ( |
|
| 2 | 58 |
<Form> |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
59 |
<div className="editor"> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
60 |
<div className="editor-left"> |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
61 |
<SlateEditor ref="editor" |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
62 |
onChange={this.onEditorChange} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
63 |
onEnterKeyDown={this.onAddNoteClick} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
64 |
onButtonClick={this.onAddNoteClick} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
65 |
onCheckboxChange={this.onCheckboxChange} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
66 |
isChecked={this.props.autoSubmit} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
67 |
isButtonDisabled={this.state.buttonDisabled} /> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
68 |
</div> |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
69 |
<div className="editor-right"> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
70 |
<FormControl |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
71 |
name="margin" |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
72 |
componentClass="textarea" |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
73 |
placeholder="Enter a margin comment for your note" |
| 78 | 74 |
inputRef={ ref => { this.marginComment = ref; } } |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
75 |
/> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
76 |
</div> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
77 |
</div> |
| 2 | 78 |
</Form> |
| 1 | 79 |
); |
80 |
} |
|
81 |
} |
|
82 |
||
83 |
NoteInput.propTypes = { |
|
84 |
addNote: PropTypes.func.isRequired |
|
85 |
}; |
|
86 |
||
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
87 |
export default NoteInput; |