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