blob: ce64018a789d7210f16f4350d5938199f7bc7644 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
import React from 'react';
import ReactRouterPropTypes from 'react-router-prop-types';
import { UserType } from './Types';
import * as qs from 'qs';
import MessageInput from './MessageInput';
import { post } from '../api';
export default class Post extends React.Component {
constructor(props) {
super(props);
let params = qs.parse(window.location.search.substring(1));
this.state = {
attach: '',
body: params.body || ''
};
this.fileinput = React.createRef();
}
postMessage = (template) => {
const { attach, body } = template;
post(body, attach)
.then(response => {
if (response.status === 200) {
const msg = response.data.newMessage;
this.props.history.push(`/${this.props.visitor.uname}/${msg.mid}`);
}
}).catch(console.log);
}
attachChanged = (event) => {
this.setState({
attach: event.target.value
});
}
bodyChanged = (event) => {
this.setState({
body: event.target.value
});
}
render() {
return (
<div className="msgs">
<article className="msg-cont">
<MessageInput rows="7" text={this.state.body} data={{ mid: 0, timestamp: '0' }} onSend={this.postMessage}>
*weather It is very cold today!
</MessageInput>
</article>
</div>
);
}
}
Post.propTypes = {
history: ReactRouterPropTypes.history.isRequired,
visitor: UserType
};
|