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/api/index.js | 8 ++++ vnext/src/ui/Message.js | 8 ++++ vnext/src/ui/MessageInput.js | 9 +++-- vnext/src/ui/Post.js | 13 +++--- vnext/src/ui/Thread.js | 61 ++++++++++++++++++----------- vnext/src/ui/__tests__/MessageInput-test.js | 59 +++++++++++++++------------- 6 files changed, 99 insertions(+), 59 deletions(-) (limited to 'vnext') diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index 2332ed48..e6b1d2ef 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -75,6 +75,14 @@ export function comment(mid, rid, body, attach) { return client.post('/api/comment', form); } +export function update(mid, rid, body) { + let form = new FormData(); + form.append('mid', mid); + form.append('rid', rid); + form.append('body', body); + return client.post('/api/update', form); +} + export function updateAvatar(newAvatar) { let form = new FormData(); form.append('avatar', newAvatar); diff --git a/vnext/src/ui/Message.js b/vnext/src/ui/Message.js index eb008bfe..fd225282 100644 --- a/vnext/src/ui/Message.js +++ b/vnext/src/ui/Message.js @@ -38,7 +38,15 @@ export default function Message({ data, visitor, children, ...rest }) { {moment.utc(data.timestamp).fromNow()} + { + visitor.uid == data.user.uid && + <> +  ·  + Edit + + } + diff --git a/vnext/src/ui/MessageInput.js b/vnext/src/ui/MessageInput.js index e4988d59..fc3596cc 100644 --- a/vnext/src/ui/MessageInput.js +++ b/vnext/src/ui/MessageInput.js @@ -21,9 +21,8 @@ export default function MessageInput({ text, data, rows, children, onSend }) { } }; useEffect(() => { - textareaRef.current.value = text || ''; updateFocus(); - }, [text]); + }, []); let handleCtrlEnter = (event) => { if (event.ctrlKey && (event.charCode == 10 || event.charCode == 13)) { @@ -37,7 +36,9 @@ export default function MessageInput({ text, data, rows, children, onSend }) { el.style.height = `${height + offset}px`; }; const [attach, setAttach] = useState(''); - const [formState, { textarea }] = useFormState(); + const [formState, { textarea }] = useFormState({ + body: text + }); let uploadValueChanged = (attach) => { setAttach(attach); }; @@ -62,7 +63,7 @@ export default function MessageInput({ text, data, rows, children, onSend }) {