added special insert flag with image uploads for handling shared image uploads

This commit is contained in:
Nouman Tahir 2021-04-23 05:03:38 +05:00
parent fec5119e28
commit a15602b2dc
2 changed files with 17 additions and 15 deletions

View File

@ -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);

View File

@ -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) {