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 (
*weather It is very cold today!
); } } Post.propTypes = { history: ReactRouterPropTypes.history.isRequired, visitor: UserType };