aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Post.js
blob: 3dc23613ec6f99ef147473cad43e4669608e3195 (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
import React, { memo } from 'react';

import ReactRouterPropTypes from 'react-router-prop-types';
import { UserType } from './Types';

import qs from 'qs';

import MessageInput from './MessageInput';

import { post } from '../api';

function PostComponent(props) {
  let params = qs.parse(window.location.search.substring(1));
  let 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);
  };
  return (
    <div className="msg-cont">
      <MessageInput rows="7" text={params.body || ''} data={{ mid: 0, timestamp: '0' }} onSend={postMessage}>
        *weather It is very cold today!
          </MessageInput>
    </div>
  );
}

export default memo(PostComponent);

PostComponent.propTypes = {
  history: ReactRouterPropTypes.history.isRequired,
  visitor: UserType
};