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