| author | salimr <riwad.salim@yahoo.fr> |
| Tue, 09 Oct 2018 19:02:17 +0200 | |
| changeset 166 | 950a2350930f |
| parent 161 | a642639dbc07 |
| child 170 | 7da1d5137b0b |
| permissions | -rw-r--r-- |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
1 |
import React, { Component } from 'react'; |
| 1 | 2 |
import PropTypes from 'prop-types'; |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
3 |
import { formatTimestamp } from '../utils'; |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
4 |
import SlateEditor from './SlateEditor'; |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
5 |
import './Note.css'; |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
6 |
|
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
7 |
class Note extends Component { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
8 |
|
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
9 |
onClickDelete = (e) => { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
10 |
e.preventDefault(); |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
11 |
e.stopPropagation(); |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
12 |
|
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
13 |
this.props.onDelete(); |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
14 |
} |
| 1 | 15 |
|
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
16 |
onClickButton = (e) => { |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
17 |
|
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
18 |
const plain = this.refs.editor.asPlain(); |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
19 |
const raw = this.refs.editor.asRaw(); |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
20 |
const html = this.refs.editor.asHtml(); |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
21 |
const categories = this.refs.editor.asCategories(); |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
22 |
// const marginComment = this.marginComment.value; |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
23 |
|
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
24 |
const data = { |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
25 |
plain, |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
26 |
raw, |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
27 |
html, |
|
109
ef62de545a8d
Allow editing margin comment.
Alexandre Segura <mex.zktk@gmail.com>
parents:
84
diff
changeset
|
28 |
categories, |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
29 |
// marginComment |
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
30 |
} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
31 |
|
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
32 |
this.props.onSave(this.props.note, data); |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
33 |
} |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
34 |
|
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
35 |
onClickClose = (e) => { |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
36 |
e.preventDefault(); |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
37 |
e.stopPropagation(); |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
38 |
|
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
39 |
this.props.onClose(); |
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
40 |
} |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
41 |
|
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
42 |
renderNoteContent() { |
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
43 |
if (this.props.isEditing) { |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
44 |
return ( |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
45 |
<div className="note-content w-100 pl-2 pt-2"> |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
46 |
<SlateEditor ref="editor" |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
47 |
onButtonClick={ this.onClickButton } |
|
138
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
109
diff
changeset
|
48 |
note={ this.props.note } |
|
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
109
diff
changeset
|
49 |
annotationCategories={ this.props.annotationCategories } /> |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
50 |
</div> |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
51 |
) |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
52 |
} |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
53 |
|
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
54 |
return ( |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
55 |
<div className="note-content w-100 pl-2 pt-2" dangerouslySetInnerHTML={{ __html: this.props.note.html }} /> |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
56 |
) |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
57 |
} |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
58 |
|
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
59 |
// renderNoteMarginComment() { |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
60 |
// if (this.props.isEditing) { |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
61 |
// return ( |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
62 |
// <div className="row"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
63 |
// <div className="note-margin-comment w-25 mt-3"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
64 |
// <input type="text" className="form-control" |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
65 |
// name="margin" |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
66 |
// componentClass="textarea" |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
67 |
// placeholder="Espace pour un commentaire de marge" |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
68 |
// defaultValue={ this.props.note.marginComment } |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
69 |
// // inputRef={ ref => { this.marginComment = ref; } } /> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
70 |
// ref={(marginComment) => { this.marginComment = marginComment; }} /> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
71 |
// </div> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
72 |
// </div> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
73 |
// ) |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
74 |
// } |
|
109
ef62de545a8d
Allow editing margin comment.
Alexandre Segura <mex.zktk@gmail.com>
parents:
84
diff
changeset
|
75 |
|
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
76 |
// return ( |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
77 |
// <div className="note-margin-comment w-25 mt-5"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
78 |
// <small className="text-muted">{ this.props.note.marginComment }</small> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
79 |
// </div> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
80 |
// ) |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
81 |
// } |
|
109
ef62de545a8d
Allow editing margin comment.
Alexandre Segura <mex.zktk@gmail.com>
parents:
84
diff
changeset
|
82 |
|
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
83 |
renderNoteRight() { |
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
84 |
if (this.props.isEditing) { |
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
85 |
return ( |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
86 |
<a onClick={this.onClickClose}> |
| 166 | 87 |
<span className="material-icons pl-2">close</span> |
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
88 |
</a> |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
89 |
); |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
90 |
} |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
91 |
|
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
92 |
return ( |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
93 |
<a onClick={this.onClickDelete}> |
| 166 | 94 |
<span className="material-icons delete-icon pl-2">delete</span> |
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
95 |
</a> |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
96 |
) |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
97 |
} |
|
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
98 |
|
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
99 |
render() { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
100 |
return ( |
| 166 | 101 |
<div id={"note-" + this.props.note._id} className="note text-sm mr-5 pt-1" |
102 |
onClick={ this.props.onClick }> |
|
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
103 |
<div className="mr-5"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
104 |
<small className="start text-warning pt-2">{ formatTimestamp(this.props.note.startedAt) }</small> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
105 |
<small className="finish text-warning pb-2">{ formatTimestamp(this.props.note.finishedAt) }</small> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
106 |
</div> |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
107 |
{ this.renderNoteContent() } |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
108 |
{/* { this.renderNoteMarginComment() } */} |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
109 |
<div className="float-right"> |
|
82
6f2999873343
Add close icon when editing note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
110 |
{ this.renderNoteRight() } |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
111 |
</div> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
143
diff
changeset
|
112 |
</div> |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
113 |
); |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
114 |
}; |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
115 |
} |
| 1 | 116 |
|
117 |
Note.propTypes = { |
|
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
118 |
note: PropTypes.object.isRequired, |
| 1 | 119 |
}; |
120 |
||
|
84
bf35a7737f94
Move logic to NotesList component.
Alexandre Segura <mex.zktk@gmail.com>
parents:
82
diff
changeset
|
121 |
export default Note; |