diff options
author | Vitaly Takmazov | 2018-06-25 15:19:09 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:53 +0300 |
commit | d5cc9b3183603e291786935832f7c50f6f3630f2 (patch) | |
tree | ccdc1869c1d447fedf74b02375bb7e44a9b78190 /vnext/src | |
parent | 1d54694dfc68a31e5f498a4c8f855b6d39456d63 (diff) |
send pm
Diffstat (limited to 'vnext/src')
-rw-r--r-- | vnext/src/components/Chat.js | 50 | ||||
-rw-r--r-- | vnext/src/components/MessageInput.js | 4 |
2 files changed, 36 insertions, 18 deletions
diff --git a/vnext/src/components/Chat.js b/vnext/src/components/Chat.js index c4d9422f..8f3a26c0 100644 --- a/vnext/src/components/Chat.js +++ b/vnext/src/components/Chat.js @@ -32,6 +32,22 @@ export default class Chat extends React.Component { } } + 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 => { + this.loadChat(this.props.match.params.user); + }) + .catch(console.log) + } + render() { const { chats } = this.state; const uname = this.props.match.params.user; @@ -39,23 +55,23 @@ export default class Chat extends React.Component { <div id="content"> <article> - { uname ? ( - <div className="chatroom"> - <ul style={chatStyle} ref="chats"> - { - chats.map((chat) => - <PM key={moment.utc(chat.timestamp).valueOf()} chat={chat} /> - ) - } - </ul> - <MessageInput data={{}} onSend={()=>{}}/> + {uname ? ( + <div className="chatroom"> + <ul style={chatStyle} ref="chats"> + { + chats.map((chat) => + <PM key={moment.utc(chat.timestamp).valueOf()} chat={chat} /> + ) + } + </ul> + <MessageInput data={{ mid: 0, timestamp: "0", to: { uname: uname } }} onSend={this.onSend} /> + </div> + ) : ( + <div className="chatroom no-selection"><p>No chat selected</p></div> + ) + } + </article> </div> - ) : ( - <div className="chatroom no-selection"><p>No chat selected</p></div> - ) - } - </article> - </div> ) } } @@ -67,5 +83,5 @@ const chatStyle = { height: '450px', display: 'flex', flexDirection: 'column-reverse', - width: '100%' + width: '100%' } diff --git a/vnext/src/components/MessageInput.js b/vnext/src/components/MessageInput.js index e30962a8..21495dd7 100644 --- a/vnext/src/components/MessageInput.js +++ b/vnext/src/components/MessageInput.js @@ -15,6 +15,7 @@ export default class MessageInput extends React.Component { isActive: false, mid: this.props.data.mid, rid: this.props.data.rid || 0, + to: this.props.data.to || {}, body: '', attach: '' } @@ -33,7 +34,8 @@ export default class MessageInput extends React.Component { mid: this.state.mid, rid: this.state.rid, body: this.state.body, - attach: this.state.attach ? input.files[0] : '' + attach: this.state.attach ? input.files[0] : '', + to: this.state.to }) this.setState({ body: '', |