| author | salimr <riwad.salim@yahoo.fr> |
| Tue, 14 Aug 2018 20:34:50 +0200 | |
| changeset 143 | cfcbf4bc66f1 |
| parent 138 | a1fb2ced3049 |
| child 157 | 5c3af4f10e92 |
| 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'; |
| 1 | 2 |
import PropTypes from 'prop-types'; |
| 5 | 3 |
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
|
4 |
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
|
5 |
|
| 1 | 6 |
|
7 |
class NoteInput extends Component { |
|
8 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
9 |
state = { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
10 |
buttonDisabled: false, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
11 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
12 |
finishedAt: null, |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
13 |
} |
| 1 | 14 |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
15 |
onEditorChange = (e) => { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
16 |
this.setState({ |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
17 |
buttonDisabled: e.state.document.length === 0, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
18 |
startedAt: e.startedAt, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
19 |
finishedAt: e.finishedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
20 |
}); |
| 1 | 21 |
} |
22 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
23 |
onAddNoteClick = () => { |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
24 |
|
| 15 | 25 |
const plain = this.refs.editor.asPlain(); |
26 |
const raw = this.refs.editor.asRaw(); |
|
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
27 |
const html = this.refs.editor.asHtml(); |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
28 |
const categories = this.refs.editor.asCategories(); |
| 78 | 29 |
const marginComment = this.marginComment.value; |
| 15 | 30 |
|
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
31 |
this.props.addNote(this.props.session, { |
| 15 | 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, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
35 |
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
|
36 |
finishedAt: now(), |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
37 |
categories: categories, |
| 78 | 38 |
marginComment: marginComment, |
| 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 |
||
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
45 |
onCheckboxChange = (e) => { |
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
46 |
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
|
47 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
48 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
49 |
componentDidMount() { |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
50 |
const text = this.refs.editor.asPlain(); |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
51 |
this.setState({ buttonDisabled: text.length === 0 }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
52 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
53 |
|
| 1 | 54 |
render() { |
55 |
return ( |
|
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
56 |
<form> |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
57 |
<div className="editor"> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
58 |
<div className="editor-left"> |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
59 |
<SlateEditor ref="editor" |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
60 |
onChange={this.onEditorChange} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
61 |
onEnterKeyDown={this.onAddNoteClick} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
62 |
onButtonClick={this.onAddNoteClick} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
63 |
onCheckboxChange={this.onCheckboxChange} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
64 |
isChecked={this.props.autoSubmit} |
|
138
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
65 |
isButtonDisabled={this.state.buttonDisabled} |
|
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
66 |
annotationCategories={ this.props.annotationCategories } /> |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
67 |
</div> |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
68 |
<div className="editor-right"> |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
69 |
<input type="textarea" className="form-control" |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
70 |
name="margin" |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
71 |
placeholder="Enter a margin comment for your note" |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
72 |
// inputRef={ ref => { this.marginComment = ref; } } |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
73 |
ref={(marginComment) => { this.marginComment = marginComment; }} |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
74 |
/> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
75 |
</div> |
|
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
76 |
</div> |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
77 |
</form> |
| 1 | 78 |
); |
79 |
} |
|
80 |
} |
|
81 |
||
82 |
NoteInput.propTypes = { |
|
83 |
addNote: PropTypes.func.isRequired |
|
84 |
}; |
|
85 |
||
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
86 |
export default NoteInput; |