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]); }, [isLoading]);
// useEffect(() => { useEffect(() => {
// if (uploadedImage && uploadedImage.url) { if (uploadedImage && uploadedImage.url && uploadedImage.shouldInsert) {
// applyImageLink({ applyImageLink({
// text, text,
// selection, selection,
// setTextAndSelection: _setTextAndSelection, setTextAndSelection: _setTextAndSelection,
// item: { url: uploadedImage.url, text: uploadedImage.hash }, item: { url: uploadedImage.url, text: uploadedImage.hash },
// isImage: !!uploadedImage, isImage: !!uploadedImage,
// }); });
// } }
// }, [uploadedImage]); }, [uploadedImage]);
useEffect(() => { useEffect(() => {
setText(draftBody); setText(draftBody);

View File

@ -103,14 +103,14 @@ class EditorContainer extends Component {
upload.forEach((el) => { upload.forEach((el) => {
if (el.filePath && el.fileName) { if (el.filePath && el.fileName) {
this.setState({ isUploading: true }); // this.setState({ isUploading: true });
const _media = { const _media = {
path: el.filePath, path: el.filePath,
mime: el.mimeType, mime: el.mimeType,
filename: el.fileName || `img_${Math.random()}.jpg`, filename: el.fileName || `img_${Math.random()}.jpg`,
}; };
this._uploadImage(_media); this._uploadImage(_media, { shouldInsert: true });
} else if (el.text) { } else if (el.text) {
this.setState({ this.setState({
draftPost: { draftPost: {
@ -370,7 +370,7 @@ class EditorContainer extends Component {
// const data = new Buffer(media.data, 'base64'); // const data = new Buffer(media.data, 'base64');
}; };
_uploadImage = async (media) => { _uploadImage = async (media, { shouldInsert } = { shouldInsert: false }) => {
const { intl, currentAccount, pinCode, isLoggedIn } = this.props; const { intl, currentAccount, pinCode, isLoggedIn } = this.props;
if (!isLoggedIn) return; if (!isLoggedIn) return;
@ -385,9 +385,11 @@ class EditorContainer extends Component {
const res = await uploadImage(media, currentAccount.name, sign); const res = await uploadImage(media, currentAccount.name, sign);
if (res.data && res.data.url) { if (res.data && res.data.url) {
res.data.hash = res.data.url.split('/').pop(); res.data.hash = res.data.url.split('/').pop();
res.data.shouldInsert = shouldInsert;
this.setState({ this.setState({
uploadedImage: res.data,
isUploading: false, isUploading: false,
uploadedImage: res.data,
}); });
} }
} catch (error) { } catch (error) {