File tree Expand file tree Collapse file tree 6 files changed +43
-21
lines changed
Expand file tree Collapse file tree 6 files changed +43
-21
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ import './App.css';
55
66import Posts from './posts/Posts' ;
77import PostDetail from './posts/PostDetail' ;
8- import PostUpdate from './posts/PostUpdate '
8+ import PostCreate from './posts/PostCreate '
99class App extends Component {
1010 render ( ) {
1111 return (
1212 < BrowserRouter >
1313 < Switch >
14- < Route exact path = '/posts/create' component = { PostUpdate } />
14+ < Route exact path = '/posts/create' component = { PostCreate } />
1515 < Route exact path = '/posts' component = { Posts } />
1616 < Route exact path = '/posts/:slug' component = { PostDetail } />
1717 < Route component = { Posts } />
Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react'
2+
3+ import PostForm from './PostForm'
4+
5+ class PostCreate extends Component {
6+ render ( ) {
7+ return (
8+ < div >
9+ < h1 > Create Post</ h1 >
10+ < PostForm />
11+ </ div >
12+ )
13+ }
14+
15+ }
16+
17+ export default PostCreate
18+
119// left for reference
220
321
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import 'whatwg-fetch'
33import cookie from 'react-cookies'
44import { Link } from 'react-router-dom'
55
6- import PostUpdate from './PostUpdate '
6+ import PostForm from './PostForm '
77
88class PostDetail extends Component {
99 constructor ( props ) {
@@ -83,12 +83,18 @@ class PostDetail extends Component {
8383 < h1 > { post . title } </ h1 >
8484 { post . slug }
8585
86- < p className = 'lead' > < Link maintainScrollPosition = { false } to = { {
86+ < p className = 'lead' >
87+ < Link maintainScrollPosition = { false } to = { {
8788 pathname : `/posts` ,
8889 state : { fromDashboard : false }
89- } } > Posts</ Link > </ p >
90+ } } > Posts</ Link >
91+ < Link maintainScrollPosition = { false } to = { {
92+ pathname : `/posts/create/` ,
93+ state : { fromDashboard : false }
94+ } } > Create Post</ Link >
95+ </ p >
9096
91- { post . owner === true ? < PostUpdate post = { post } postItemUpdated = { this . handlePostItemUpdated } /> : "" }
97+ { post . owner === true ? < PostForm post = { post } postItemUpdated = { this . handlePostItemUpdated } /> : "" }
9298 </ div >
9399 }
94100 </ div > : "Loading..." } </ p >
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import 'whatwg-fetch'
33import cookie from 'react-cookies'
44import moment from 'moment'
55
6- class PostUpdate extends Component {
6+ class PostForm extends Component {
77 constructor ( props ) {
88 super ( props )
99 this . handleSubmit = this . handleSubmit . bind ( this )
@@ -44,7 +44,6 @@ class PostUpdate extends Component {
4444 if ( thisComp . props . newPostItemCreated ) {
4545 thisComp . props . newPostItemCreated ( responseData )
4646 }
47- thisComp . defaultState ( )
4847 thisComp . clearForm ( )
4948 } ) . catch ( function ( error ) {
5049 console . log ( "error" , error )
@@ -125,6 +124,7 @@ class PostUpdate extends Component {
125124 event . preventDefault ( )
126125 }
127126 this . postCreateForm . reset ( )
127+ this . defaultState ( )
128128 }
129129
130130
@@ -209,11 +209,11 @@ class PostUpdate extends Component {
209209 required = 'required' />
210210 </ div >
211211 < button type = 'submit' className = 'btn btn-primary' > Save</ button >
212- < button className = { `btn btn-secondary ${ cancelClass } ` } onClick = { this . clearForm } > Cancel </ button >
212+ < button className = { `btn btn-secondary` } onClick = { this . clearForm } > Clear </ button >
213213 </ form >
214214 )
215215 }
216216
217217}
218218
219- export default PostUpdate
219+ export default PostForm
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import 'whatwg-fetch'
33import cookie from 'react-cookies'
4-
5- import PostUpdate from './PostUpdate'
4+ import { Link } from 'react-router-dom'
65import PostInline from './PostInline'
76
87class Posts extends Component {
@@ -40,7 +39,7 @@ class Posts extends Component {
4039 }
4140
4241 handleNewPost ( postItemData ) {
43- console . log ( postItemData )
42+ // console.log(postItemData)
4443 let currentPosts = this . state . posts
4544 currentPosts . unshift ( postItemData ) // unshift
4645 this . setState ( {
@@ -79,18 +78,17 @@ class Posts extends Component {
7978 return (
8079 < div >
8180 < h1 > Hello World</ h1 >
81+ < Link maintainScrollPosition = { false } to = { {
82+ pathname : `/posts/create/` ,
83+ state : { fromDashboard : false }
84+ } } > Create Post</ Link >
85+
8286 < button onClick = { this . togglePostListClass } > Toggle Class</ button >
8387 { posts . length > 0 ? posts . map ( ( postItem , index ) => {
8488 return (
8589 < PostInline post = { postItem } elClass = { postsListClass } />
8690 )
8791 } ) : < p > No Posts Found</ p > }
88- { ( csrfToken !== undefined && csrfToken !== null ) ?
89- < div className = 'my-5' >
90- < PostUpdate newPostItemCreated = { this . handleNewPost } />
91- </ div >
92- : "" }
93-
9492 </ div >
9593 ) ;
9694 }
You can’t perform that action at this time.
0 commit comments