diff options
Diffstat (limited to 'vnext/src/components/Thread.js')
-rw-r--r-- | vnext/src/components/Thread.js | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index 17c5b55c..b1e1abb3 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -12,6 +12,8 @@ import Button from './Button'; import { format } from '../utils/embed'; +import { getMessages, comment } from '../api'; + export default class Thread extends React.Component { constructor(props) { super(props); @@ -36,16 +38,12 @@ export default class Thread extends React.Component { if (this.props.visitor && this.props.visitor.hash) { params.hash = this.props.visitor.hash }; - const url = `https://api.juick.com/thread?${qs.stringify(params)}`; - fetch(url) + getMessages('/thread', params) .then(response => { - return response.json() - }) - .then(data => { - let msg = data.shift(); + let msg = response.data.shift(); this.setState({ msg: msg, - replies: data, + replies: response.data, active: 0 }) } @@ -62,18 +60,8 @@ export default class Thread extends React.Component { }) } 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 => { + const { mid, rid, body, attach } = template; + comment(mid, rid, body, attach).then(res => { this.loadReplies() }) .catch(console.log) |