From ee5f3a4a78cd9a4cc2ed259ce599db95765f24ce Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 11 Jun 2019 14:56:08 +0300 Subject: Message editing --- vnext/src/ui/Post.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'vnext/src/ui/Post.js') diff --git a/vnext/src/ui/Post.js b/vnext/src/ui/Post.js index 3dc23613..dc1c7a9d 100644 --- a/vnext/src/ui/Post.js +++ b/vnext/src/ui/Post.js @@ -7,23 +7,25 @@ import qs from 'qs'; import MessageInput from './MessageInput'; -import { post } from '../api'; +import { post, update } from '../api'; -function PostComponent(props) { +function PostComponent({ location, visitor, history }) { + let draftMessage = (location.state || {}).draft || {}; let params = qs.parse(window.location.search.substring(1)); let postMessage = (template) => { const { attach, body } = template; - post(body, attach) + const postAction = draftMessage.mid ? update(draftMessage.mid, 0, body) : post(body, attach); + postAction .then(response => { if (response.status === 200) { const msg = response.data.newMessage; - this.props.history.push(`/${this.props.visitor.uname}/${msg.mid}`); + history.push(`/${visitor.uname}/${msg.mid}`); } }).catch(console.log); }; return (
- + *weather It is very cold today!
@@ -33,6 +35,7 @@ function PostComponent(props) { export default memo(PostComponent); PostComponent.propTypes = { + location: ReactRouterPropTypes.location, history: ReactRouterPropTypes.history.isRequired, visitor: UserType }; -- cgit v1.2.3