Merge branch 'development' of https://github.com/ecency/ecency-mobile into development

This commit is contained in:
feruz 2021-04-04 00:04:36 +03:00
commit 68b898b32f
4 changed files with 116 additions and 68 deletions

View File

@ -28,9 +28,10 @@ export default async ({ text, selection, setTextAndSelection, item, isImage = nu
} else {
newText = replaceBetween(text, selection, `\n${imagePrefix}[${itemText}](${itemUrl})\n`);
if (isImage) {
const newIndex = newText && newText.indexOf(itemUrl) + 2 + itemUrl.length;
newSelection = {
start: newText && newText.length,
end: newText && newText.length,
start: newIndex,
end: newIndex,
};
} else {
newSelection = {

View File

@ -14,7 +14,6 @@ export default EStyleSheet.create({
paddingHorizontal: 16,
color: '$primaryBlack',
backgroundColor: '$primaryBackgroundColor',
minHeight: 200,
textAlignVertical: 'top',
},
previewContainer: {

View File

@ -41,7 +41,7 @@ import { ThemeContainer } from '../../../containers';
import styles from './markdownEditorStyles';
import applySnippet from './formats/applySnippet';
const MIN_BODY_INPUT_HEIGHT = 200;
const MIN_BODY_INPUT_HEIGHT = 300;
const MarkdownEditorView = ({
draftBody,
@ -165,7 +165,7 @@ const MarkdownEditorView = ({
};
const _handleOnContentSizeChange = async (event) => {
const height = Math.max(MIN_BODY_INPUT_HEIGHT, event.nativeEvent.contentSize.height + 30);
const height = Math.max(MIN_BODY_INPUT_HEIGHT, event.nativeEvent.contentSize.height + 100);
setBodyInputHeight(height);
};

View File

@ -352,22 +352,16 @@ class EditorContainer extends Component {
});
};
_handleMediaOnSelected = (media) => {
this.setState(
{
isUploading: true,
},
async () => {
if (media.length > 0) {
for (let index = 0; index < media.length; index++) {
const element = media[index];
await this._uploadImage(element);
}
} else {
await this._uploadImage(media);
}
},
);
_handleMediaOnSelected = async (media) => {
if (media.length > 0) {
for (let index = 0; index < media.length; index++) {
const element = media[index];
await this._uploadImage(element);
}
} else {
await this._uploadImage(media);
}
// For new image api
// const { currentAccount } = this.props;
// const digitPinCode = await getPinCode();
@ -381,59 +375,113 @@ class EditorContainer extends Component {
if (!isLoggedIn) return;
this.setState({
isUploading: true,
});
let sign = await signImage(media, currentAccount, pinCode);
uploadImage(media, currentAccount.name, sign)
.then((res) => {
if (res.data && res.data.url) {
res.data.hash = res.data.url.split('/').pop();
this.setState({
uploadedImage: res.data,
isUploading: false,
});
}
})
.catch((error) => {
console.log(error, error.message);
if (error.toString().includes('code 413')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.payloadTooLarge',
}),
);
} else if (error.toString().includes('code 429')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.quotaExceeded',
}),
);
} else if (error.toString().includes('code 400')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.invalidImage',
}),
);
} else {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
error.message || error.toString(),
);
}
try {
const res = await uploadImage(media, currentAccount.name, sign);
if (res.data && res.data.url) {
res.data.hash = res.data.url.split('/').pop();
this.setState({
uploadedImage: res.data,
isUploading: false,
});
}
} catch (error) {
console.log(error, error.message);
if (error.toString().includes('code 413')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.payloadTooLarge',
}),
);
} else if (error.toString().includes('code 429')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.quotaExceeded',
}),
);
} else if (error.toString().includes('code 400')) {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
intl.formatMessage({
id: 'alert.invalidImage',
}),
);
} else {
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
error.message || error.toString(),
);
}
this.setState({
isUploading: false,
});
}
// uploadImage(media, currentAccount.name, sign).then((res) => {
// if (res.data && res.data.url) {
// res.data.hash = res.data.url.split('/').pop();
// this.setState({
// uploadedImage: res.data,
// isUploading: false,
// });
// }
// })
// .catch((error) => {
// console.log(error, error.message);
// if (error.toString().includes('code 413')) {
// Alert.alert(
// intl.formatMessage({
// id: 'alert.fail',
// }),
// intl.formatMessage({
// id: 'alert.payloadTooLarge',
// }),
// );
// } else if (error.toString().includes('code 429')) {
// Alert.alert(
// intl.formatMessage({
// id: 'alert.fail',
// }),
// intl.formatMessage({
// id: 'alert.quotaExceeded',
// }),
// );
// } else if (error.toString().includes('code 400')) {
// Alert.alert(
// intl.formatMessage({
// id: 'alert.fail',
// }),
// intl.formatMessage({
// id: 'alert.invalidImage',
// }),
// );
// } else {
// Alert.alert(
// intl.formatMessage({
// id: 'alert.fail',
// }),
// error.message || error.toString(),
// );
// }
// this.setState({
// isUploading: false,
// });
// });
};
_handleMediaOnSelectFailure = (error) => {