diff options
author | Vitaly Takmazov | 2018-06-28 12:09:09 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:53 +0300 |
commit | 23d291df6146914683d5c414965a9f4396e464e2 (patch) | |
tree | 13e2a6993ac12a3a1ec984014633835ae3459ae7 /vnext/src/components | |
parent | 43ad3c12adc0372bebeef4cba26645811d1720af (diff) |
working Post component
Diffstat (limited to 'vnext/src/components')
-rw-r--r-- | vnext/src/components/Post.js | 45 |
1 files changed, 41 insertions, 4 deletions
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 ( <article> - <form action="/" method="post" id="postmsg" encType="multipart/form-data"> + <form id="postmsg"> <p style={{ textAlign: 'left' }}> <b>Фото:</b> <span id="attachmentfile"> - <input style={{ width: '100%' }} type="file" name="attach"/> <i>(JPG/PNG)</i></span> + <input style={{ width: '100%' }} type="file" name="attach" ref={this.fileinput} value={this.state.attach} onChange={this.attachChanged}/> <i>(JPG/PNG)</i></span> </p> <p> - <textarea name="body" className="newmessage" rows="7" cols="10" placeholder="*weather It's very cold today!"></textarea> + <textarea name="body" value={this.state.body} onChange={this.bodyChanged} className="newmessage" rows="7" cols="10" placeholder="*weather It's very cold today!"></textarea> <br/> - <input type="submit" className="subm" value=" POST "/> + <Button className="subm" onClick={this.submit}>POST</Button> </p> </form> </article> |