aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vnext/src/components/MessageInput.js3
-rw-r--r--vnext/src/components/Thread.js22
2 files changed, 23 insertions, 2 deletions
diff --git a/vnext/src/components/MessageInput.js b/vnext/src/components/MessageInput.js
index a276225b..30c411fd 100644
--- a/vnext/src/components/MessageInput.js
+++ b/vnext/src/components/MessageInput.js
@@ -27,11 +27,12 @@ export default class MessageInput extends React.Component {
onSubmit(event) {
event.preventDefault();
+ const input = this.fileinput.current;
this.props.onSend({
mid: this.state.mid,
rid: this.state.rid,
body: this.state.body,
- attach: this.state.attach
+ attach: this.state.attach ? input.files[0] : ''
})
}
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js
index 96b7e093..cfef2372 100644
--- a/vnext/src/components/Thread.js
+++ b/vnext/src/components/Thread.js
@@ -18,6 +18,7 @@ export default class Thread extends React.Component {
replies: []
};
this.loaded = this.loaded.bind(this);
+ this.postComment = this.postComment.bind(this);
}
componentDidMount() {
document.body.scrollTop = 0;
@@ -52,6 +53,25 @@ export default class Thread extends React.Component {
loaded() {
return this.state.msg.mid;
}
+
+ postComment(template) {
+ const url = `https://api.juick.com/comment?hash=${this.props.visitor.hash}`;
+ let form = new FormData();
+ form.append('mid', template.mid);
+ form.append('rid', template.rid);
+ form.append('body', template.body);
+ form.append('attach', template.attach);
+ fetch(url, {
+ method: 'POST',
+ body: form
+ }).then(response => {
+ return response.json()
+ }).then(res => {
+ this.loadReplies()
+ })
+ .catch(console.log)
+ }
+
render() {
const msg = this.state.msg;
return (
@@ -61,7 +81,7 @@ export default class Thread extends React.Component {
{
this.loaded() ? (
<Message data={msg} visitor={this.props.visitor}>
- <MessageInput data={msg} onSend={console.log} />
+ <MessageInput data={msg} onSend={this.postComment} />
<Recommendations src={msg.recommendations} />
</Message>
) : (