Skip to content

Commit

Permalink
fix(client): fix paste upload image can't update preview area after s…
Browse files Browse the repository at this point in the history
…uccess
  • Loading branch information
lizheming committed Dec 19, 2020
1 parent 353a14c commit 2103295
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/client/src/components/CommentBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _insertAtCaret(field, val) {
}
}

function onPasteFactory(editorRef, uploadImage = new Function, insertAtCaret) {
function onPasteFactory(editorRef, uploadImage = new Function, insertAtCaret, onChange) {
return function(e) {
const field = editorRef.current;
const clipboardData = 'clipboardData' in e ? e.clipboardData : (e.originalEvent && e.originalEvent.clipboardData || window.clipboardData);
Expand All @@ -84,9 +84,10 @@ function onPasteFactory(editorRef, uploadImage = new Function, insertAtCaret) {
files.forEach(file => {
const uploadText = `![Uploading ${file['name']}]()`;
insertAtCaret(field, uploadText);
return Promise.resolve().then(_ => uploadImage(file)).then(ret =>
(field.value = field.value.replace(uploadText, `\r\n![${file.name}](${ret.data || ret})`))
);
return Promise.resolve().then(_ => uploadImage(file)).then(ret => {
field.value = field.value.replace(uploadText, `\r\n![${file.name}](${ret.data || ret})`);
onChange({target: field});
});
});
}
}
Expand Down Expand Up @@ -162,7 +163,7 @@ export default function({
insertAtCaret(e.target, ' ');
}
}, []);
const onPaste = useCallback(onPasteFactory(editorRef, ctx.uploadImage, insertAtCaret), []);
const onPaste = useCallback(onPasteFactory(editorRef, ctx.uploadImage, insertAtCaret, onChange), []);
const submitComment = useCallback(() => {
if(requiredFields.indexOf('nick') > -1 && comment.nick.length < 2) {
inputsRef.nick.current.focus();
Expand Down

0 comments on commit 2103295

Please sign in to comment.