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/api/index.js | 7 +++++++ vnext/src/components/Post.js | 45 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) (limited to 'vnext') diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index 00605d87..653360f5 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -56,6 +56,13 @@ export function getMessages(path, params) { }) } +export function post(body, attach) { + let form = new FormData() + form.append('attach', attach) + form.append('body', body) + return client.post('/post', form); +} + export function comment(mid, rid, body, attach) { let form = new FormData(); form.append('mid', mid); 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