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/Chat.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'vnext/src/components/Chat.js') diff --git a/vnext/src/components/Chat.js b/vnext/src/components/Chat.js index 8f3a26c0..c7a5c3ff 100644 --- a/vnext/src/components/Chat.js +++ b/vnext/src/components/Chat.js @@ -4,6 +4,8 @@ import moment from 'moment'; import PM from './PM'; import MessageInput from './MessageInput'; +import { getChat, pm } from '../api'; + export default class Chat extends React.Component { constructor(props) { super(props); @@ -22,30 +24,20 @@ export default class Chat extends React.Component { chats: [] }); if (hash && uname) { - fetch(`https://api.juick.com/pm?uname=${uname}&hash=${hash}`) - .then(response => response.json()) - .then(jsonResponse => { + getChat(uname) + .then(response => { this.setState({ - chats: jsonResponse + chats: response.data }); }); } } onSend = (template) => { - const url = `https://api.juick.com/pm?hash=${this.props.visitor.hash}`; - let form = new FormData(); - form.append('body', template.body); - form.append('uname', template.to.uname); - fetch(url, { - method: 'POST', - body: form - }).then(response => { - return response.json() - }).then(res => { + pm(template.to.uname, template.body) + .then(res => { this.loadChat(this.props.match.params.user); - }) - .catch(console.log) + }).catch(console.log) } render() { -- cgit v1.2.3