aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Post.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-06-11 14:56:08 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:55 +0300
commitee5f3a4a78cd9a4cc2ed259ce599db95765f24ce (patch)
tree7e0243d335af5b93c49d5d29ce80988bbed8b220 /vnext/src/ui/Post.js
parentbe48cd1cccacc0cf5b0f6c84455ab54a6a7bf672 (diff)
Message editing
Diffstat (limited to 'vnext/src/ui/Post.js')
-rw-r--r--vnext/src/ui/Post.js13
1 files changed, 8 insertions, 5 deletions
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 (
<div className="msg-cont">
- <MessageInput rows="7" text={params.body || ''} data={{ mid: 0, timestamp: '0' }} onSend={postMessage}>
+ <MessageInput rows="7" text={params.body || draftMessage.body || ''} data={{ mid: 0, timestamp: '0' }} onSend={postMessage}>
*weather It is very cold today!
</MessageInput>
</div>
@@ -33,6 +35,7 @@ function PostComponent(props) {
export default memo(PostComponent);
PostComponent.propTypes = {
+ location: ReactRouterPropTypes.location,
history: ReactRouterPropTypes.history.isRequired,
visitor: UserType
};