diff --git a/src/components/markdownEditor/view/markdownEditorView.js b/src/components/markdownEditor/view/markdownEditorView.js index 21019a1c0..a2cb3f834 100644 --- a/src/components/markdownEditor/view/markdownEditorView.js +++ b/src/components/markdownEditor/view/markdownEditorView.js @@ -109,17 +109,17 @@ const MarkdownEditorView = ({ } }, [isLoading]); - // useEffect(() => { - // if (uploadedImage && uploadedImage.url) { - // applyImageLink({ - // text, - // selection, - // setTextAndSelection: _setTextAndSelection, - // item: { url: uploadedImage.url, text: uploadedImage.hash }, - // isImage: !!uploadedImage, - // }); - // } - // }, [uploadedImage]); + useEffect(() => { + if (uploadedImage && uploadedImage.url && uploadedImage.shouldInsert) { + applyImageLink({ + text, + selection, + setTextAndSelection: _setTextAndSelection, + item: { url: uploadedImage.url, text: uploadedImage.hash }, + isImage: !!uploadedImage, + }); + } + }, [uploadedImage]); useEffect(() => { setText(draftBody); diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index a506b2221..0cfc5a974 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -103,14 +103,14 @@ class EditorContainer extends Component { upload.forEach((el) => { if (el.filePath && el.fileName) { - this.setState({ isUploading: true }); + // this.setState({ isUploading: true }); const _media = { path: el.filePath, mime: el.mimeType, filename: el.fileName || `img_${Math.random()}.jpg`, }; - this._uploadImage(_media); + this._uploadImage(_media, { shouldInsert: true }); } else if (el.text) { this.setState({ draftPost: { @@ -370,7 +370,7 @@ class EditorContainer extends Component { // const data = new Buffer(media.data, 'base64'); }; - _uploadImage = async (media) => { + _uploadImage = async (media, { shouldInsert } = { shouldInsert: false }) => { const { intl, currentAccount, pinCode, isLoggedIn } = this.props; if (!isLoggedIn) return; @@ -385,9 +385,11 @@ class EditorContainer extends Component { const res = await uploadImage(media, currentAccount.name, sign); if (res.data && res.data.url) { res.data.hash = res.data.url.split('/').pop(); + res.data.shouldInsert = shouldInsert; + this.setState({ - uploadedImage: res.data, isUploading: false, + uploadedImage: res.data, }); } } catch (error) {