From 40b8cd9853dd87deb90afdda0f5af78faa414f2b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Jun 2018 14:33:34 +0300 Subject: fetch -> axios --- vnext/src/components/Thread.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'vnext/src/components/Thread.js') 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) -- cgit v1.2.3