From 23d291df6146914683d5c414965a9f4396e464e2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 28 Jun 2018 12:09:09 +0300 Subject: working Post component --- vnext/src/components/Post.js | 45 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'vnext/src/components') diff --git a/vnext/src/components/Post.js b/vnext/src/components/Post.js index 3256bbf6..8dd8f37a 100644 --- a/vnext/src/components/Post.js +++ b/vnext/src/components/Post.js @@ -1,18 +1,55 @@ import React from 'react'; +import Button from './Button'; + +import { post } from '../api'; + export default class Post extends React.Component { + constructor(props) { + super(props) + this.state = { + attach : '', + body: '' + } + this.fileinput = React.createRef(); + console.log(props) + } + submit = (event) => { + if (event.preventDefault) event.preventDefault(); + const {attach, body} = this.state; + const input = this.fileinput.current; + post(body, attach ? input.files[0] : '') + .then(response => { + console.log(response) + if (response.status === 200) { + const msg = response.data.newMessage; + console.log(msg) + 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 (
-
+

Фото: - (JPG/PNG) + (JPG/PNG)

- +
- +

-- cgit v1.2.3