diff options
Diffstat (limited to 'vnext/src/components/Chat.js')
-rw-r--r-- | vnext/src/components/Chat.js | 24 |
1 files changed, 8 insertions, 16 deletions
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() { |