| author | ymh <ymh.work@gmail.com> |
| Tue, 04 Dec 2018 18:17:56 +0100 | |
| changeset 191 | 3f71ad81a5a9 |
| parent 173 | 0e6703cd0968 |
| child 194 | d19ba6045e82 |
| 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'; |
| 1 | 5 |
|
6 |
class NoteInput extends Component { |
|
7 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
8 |
constructor(props) { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
9 |
super(props); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
10 |
this.editorInst = React.createRef(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
11 |
} |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
12 |
|
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
13 |
get editor() { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
14 |
return this.editorInst.current; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
15 |
} |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
16 |
state = { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
17 |
buttonDisabled: false, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
18 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
19 |
finishedAt: null, |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
20 |
} |
| 1 | 21 |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
22 |
onEditorChange = (e) => { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
23 |
this.setState({ |
| 157 | 24 |
buttonDisabled: e.value.document === 0, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
25 |
startedAt: e.startedAt, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
26 |
finishedAt: e.finishedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
27 |
}); |
| 1 | 28 |
} |
29 |
||
| 173 | 30 |
submitNote = () => { |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
31 |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
32 |
const plain = this.editor.asPlain(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
33 |
const raw = this.editor.asRaw(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
34 |
const html = this.editor.asHtml(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
35 |
const categories = this.editor.asCategories(); |
| 157 | 36 |
// const marginComment = this.marginComment.value; |
| 15 | 37 |
|
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
38 |
this.props.addNote(this.props.session, { |
| 15 | 39 |
plain: plain, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
40 |
raw: raw, |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
41 |
html: html, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
42 |
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
|
43 |
finishedAt: now(), |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
44 |
categories: categories, |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
45 |
|
| 157 | 46 |
// marginComment: marginComment, |
| 15 | 47 |
}); |
48 |
||
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
49 |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
50 |
this.editor.clear(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
51 |
setTimeout(() => this.editor.focus(), 250); |
| 1 | 52 |
} |
53 |
||
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
54 |
componentDidMount() { |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
55 |
if(this.editor) { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
56 |
const text = this.editor.asPlain(); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
57 |
this.setState({ buttonDisabled: text.length === 0 }); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
58 |
} |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
59 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
60 |
|
| 1 | 61 |
render() { |
62 |
return ( |
|
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
63 |
<form> |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
64 |
<div className="editor mb-3"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
65 |
<div className="editor-left sticky-bottom px-2"> |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
66 |
<SlateEditor editorRef={this.editorInst} |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
67 |
onChange={this.onEditorChange} |
| 173 | 68 |
submitNote={this.submitNote} |
|
138
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
69 |
isButtonDisabled={this.state.buttonDisabled} |
|
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
70 |
annotationCategories={ this.props.annotationCategories } /> |
| 157 | 71 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
72 |
</div> |
| 157 | 73 |
{/* <div className="editor-right w-25 pl-2 border-0 sticky-bottom"> |
74 |
<input type="textarea" className="form-control h-100" |
|
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
75 |
name="margin" |
| 157 | 76 |
placeholder="Espace de commentaire pour votre note" |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
77 |
// 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
|
78 |
ref={(marginComment) => { this.marginComment = marginComment; }} |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
79 |
/> |
| 157 | 80 |
</div> */} |
|
35
97106bacb24e
Improve session page design.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
81 |
</div> |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
138
diff
changeset
|
82 |
</form> |
| 1 | 83 |
); |
84 |
} |
|
85 |
} |
|
86 |
||
87 |
NoteInput.propTypes = { |
|
88 |
addNote: PropTypes.func.isRequired |
|
89 |
}; |
|
90 |
||
|
125
c653f49fabfb
remove unecessary dependencies to Redux
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
91 |
export default NoteInput; |