1
1
import React from 'react' ;
2
- import { Link } from 'react-router-dom' ;
2
+ import { Link , Redirect } from 'react-router-dom' ;
3
3
import { List , ListItem } from 'material-ui/List' ;
4
4
import ActionInfo from 'material-ui/svg-icons/action/info' ;
5
5
import Divider from 'material-ui/Divider' ;
@@ -31,6 +31,7 @@ class Directory extends React.Component {
31
31
isOpen : false ,
32
32
docName : '' ,
33
33
docPass : '' ,
34
+ newDocId : '' ,
34
35
}
35
36
}
36
37
logout ( ) {
@@ -57,6 +58,7 @@ class Directory extends React.Component {
57
58
. catch ( ( err ) => console . log ( err ) )
58
59
}
59
60
componentDidMount ( ) {
61
+ console . log ( this . props . store . get ( 'userId' ) ) ;
60
62
this . ownedByAll ( )
61
63
}
62
64
filter ( event , value ) {
@@ -151,7 +153,29 @@ class Directory extends React.Component {
151
153
} )
152
154
}
153
155
newDocument ( ) {
154
-
156
+ fetch ( 'http://localhost:3000/documents/new/' + this . props . store . get ( 'userId' ) , {
157
+ method : 'POST' ,
158
+ headers : {
159
+ "Content-Type" : "application/json"
160
+ } ,
161
+ body : JSON . stringify ( {
162
+ title : this . state . docName ,
163
+ //password: newPassword,
164
+ // collaborators: newCollaborators
165
+
166
+ } )
167
+ } )
168
+ . then ( ( response ) => {
169
+ return response . json ( )
170
+ } )
171
+ . then ( ( resp ) => {
172
+ console . log ( "DOC" , resp . document ) ;
173
+ console . log ( "DOCID" , resp . document . _id ) ;
174
+ this . setState ( {
175
+ newDocId : resp . document . _id
176
+ } )
177
+ } )
178
+ . catch ( ( err ) => console . log ( err ) )
155
179
}
156
180
render ( ) {
157
181
const testDoc = {
@@ -179,6 +203,13 @@ class Directory extends React.Component {
179
203
primary = { true }
180
204
/> ,
181
205
] ;
206
+ console . log ( this . state . newDocId ) ;
207
+ if ( this . state . newDocId ) {
208
+ return (
209
+
210
+ < Redirect to = { "/editor/" + this . state . newDocId } />
211
+ )
212
+ }
182
213
return (
183
214
< div >
184
215
< h1 style = { { textAlign : 'center' , fontSize : '40px' , paddingTop : '20px' } } > Document Directory</ h1 >
@@ -198,7 +229,7 @@ class Directory extends React.Component {
198
229
open = { this . state . modalOpen }
199
230
onRequestClose = { this . modalClose . bind ( this ) }
200
231
>
201
- < form className = "commentForm" onSubmit = { this . handleSubmit } >
232
+ < form className = "commentForm" onSubmit = { this . newDocument . bind ( this ) } >
202
233
< input
203
234
type = "text"
204
235
placeholder = "Your Document Name"
0 commit comments