@@ -17,16 +17,34 @@ import * as React from "react";
17
17
import { useEffect , useState } from "react" ;
18
18
import toast , { Toaster } from "react-hot-toast" ;
19
19
20
+ import { Editor } from "react-draft-wysiwyg" ;
21
+ import { EditorState , convertToRaw } from "draft-js" ;
22
+ import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css" ;
23
+ import draftToHtml from "draftjs-to-html" ;
24
+
25
+
20
26
export default function SideBarModify ( { open, toggleDrawerModify, deviceId } ) {
21
27
const [ title , setTitle ] = useState ( "" ) ;
22
28
const [ description , setDescription ] = useState ( "" ) ;
23
29
const [ photo , setPhoto ] = useState ( "" ) ;
24
30
const [ image , setImage ] = useState ( "" ) ;
31
+ const [ editorState , setEditorState ] = useState ( EditorState . createEmpty ( ) ) ;
32
+ const [ inputEditorState , setInputEditorState ] = useState ( "" ) ;
33
+
34
+
35
+ const handleEditorChange = ( e ) => {
36
+ setEditorState ( e ) ;
37
+ setInputEditorState ( draftToHtml ( convertToRaw ( e . getCurrentContent ( ) ) ) ) ;
38
+
39
+ }
40
+
41
+ console . log ( inputEditorState ) ;
25
42
26
43
const newBlog = async ( e ) => {
27
44
e . preventDefault ( ) ;
28
45
29
- if ( ! title || ! description || ! photo ) {
46
+ if ( ! title || ! description || ! photo || ! editorState || ! inputEditorState ) {
47
+ console . log ( title , description , photo , editorState ) ;
30
48
toast . error ( "Veuillez remplir tous les champs" ) ;
31
49
return ;
32
50
}
@@ -35,6 +53,10 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
35
53
title,
36
54
description,
37
55
photo,
56
+ editorState,
57
+ inputEditorState
58
+
59
+
38
60
} ;
39
61
try {
40
62
const response = await axios . post (
@@ -52,9 +74,10 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
52
74
53
75
const list = ( ) => (
54
76
< >
77
+
55
78
< Box
56
79
sx = { {
57
- width : 350 ,
80
+ width : 1450 ,
58
81
p : 2 ,
59
82
justifyContent : "center" ,
60
83
alignItems : "center" ,
@@ -63,14 +86,40 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
63
86
} }
64
87
role = "presentation"
65
88
>
89
+
90
+
66
91
< Typography
67
92
variant = "h6"
68
93
sx = { {
69
94
marginBottom : 4 ,
70
95
} }
71
96
>
72
97
Ajout d'un nouveau blog
98
+
99
+ < div >
100
+ < Editor
101
+
102
+ placeholder = 'Write your blog here...'
103
+
104
+ editorState = { editorState }
105
+
106
+ toolbarClassName = "toolbarClassName"
107
+ wrapperClassName = "wrapperClassName"
108
+ editorClassName = "editorClassName"
109
+ onEditorStateChange = { handleEditorChange }
110
+ editorStyle = { { border : "1px solid black" , minHeight : "180px" , padding : "10px" , borderRadius : "5px" , boxShadow : "0 0 10px 0 rgba(0,0,0,0.2)" } }
111
+
112
+ />
113
+
114
+ < textarea disabled value = {
115
+ draftToHtml ( convertToRaw ( editorState . getCurrentContent ( ) ) )
116
+
117
+ } >
118
+
119
+ </ textarea >
120
+ </ div >
73
121
</ Typography >
122
+
74
123
< IconButton
75
124
sx = { {
76
125
position : "absolute" ,
@@ -83,7 +132,10 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
83
132
>
84
133
< CloseIcon />
85
134
</ IconButton >
135
+
86
136
< >
137
+
138
+
87
139
< TextField
88
140
sx = { { marginBottom : 2 } }
89
141
id = "outlined-search"
@@ -96,7 +148,9 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
96
148
InputLabelProps = { { className : "inputLabel" } }
97
149
InputProps = { { className : "input" } }
98
150
/>
151
+
99
152
< TextField
153
+
100
154
sx = { { marginBottom : 2 } }
101
155
id = "outlined-search"
102
156
type = { "text" }
@@ -107,7 +161,9 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
107
161
fullWidth
108
162
InputLabelProps = { { className : "inputLabel" } }
109
163
InputProps = { { className : "input" } }
110
- />
164
+ >
165
+
166
+ </ TextField >
111
167
112
168
< TextField
113
169
sx = { { marginBottom : 2 } }
@@ -140,6 +196,8 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
140
196
image = { photo ? photo : "" }
141
197
alt = ""
142
198
/>
199
+
200
+
143
201
</ >
144
202
) }
145
203
@@ -174,3 +232,5 @@ export default function SideBarModify({ open, toggleDrawerModify, deviceId }) {
174
232
</ div >
175
233
) ;
176
234
}
235
+
236
+
0 commit comments