-
Notifications
You must be signed in to change notification settings - Fork 3
/
CommentAdd.js
75 lines (70 loc) · 1.98 KB
/
CommentAdd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component } from 'react'
import axios from 'axios'
import './Commentadd.css'
//NHI -- I copied and pasted from your add link component and fiddled around... but I don't totally know what to do so I'm handing things off.
class CommentAdd extends Component {
constructor() {
super()
this.state = {
comment: '',
name: ''
}
this.handleSubmit = this.handleSubmit.bind(this)
this.handlePost = this.handlePost.bind(this)
}
handleSubmit(e) {
e.preventDefault()
this.setState(
{
// i don't know if this is what I am supposed to be calling here...
comment: this.refs.comment.value,
name: this.refs.name.value
},
this.handlePost
)
}
handlePost(e) {
e.preventDefault()
axios
//changed the .post link because it's the api/comments.... but is it comments of individual post? do we need an ID involved here?
// on the back end I believe it's api/comments/:id ??? but i'm not sure how to call that here.
.post('http://wobble-back-end.herokuapp.com/api/comments', {
//do these need to be this.state.comments.comment and this.state.comments.name????
comment: this.state.comment,
name: this.state.name
})
.then(data => {
console.log(data)
}).catch(err => console.log('Not working my b', err))
// console.log(this.state.comment)
}
render() {
return (
<div>
<form>
<input
className="add-comment"
type="textarea"
ref="comment"
placeholder="Add comment!"
/>
<br />
<input
className="add-comment-name"
type="text"
ref="name"
placeholder="Name!"
/>
<br />
<input
className="submit-btn"
type="submit"
value="Submit"
onClick={this.handleSubmit}
/>
</form>
</div>
)
}
}
export default CommentAdd