added reply save draft

This commit is contained in:
u-e 2019-02-13 15:58:49 +03:00
parent abbac5f4bd
commit d4f7911437
4 changed files with 54 additions and 22 deletions

View File

@ -18,9 +18,6 @@ export default EStyleSheet.create({
// height: 50,
marginTop: 10,
},
code: {
fontFamily: '$editorFont',
},
commentContainer: {
paddingHorizontal: 0,
marginTop: 10,
@ -44,4 +41,13 @@ export default EStyleSheet.create({
padding: 10,
backgroundColor: '$tableTrColor',
},
blockquote: {
borderLeftWidth: 5,
borderColor: '$darkIconColor',
paddingLeft: 5,
},
code: {
backgroundColor: '$darkIconColor',
fontFamily: '$editorFont',
},
});

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
import { Alert } from 'react-native';
import { Alert, AsyncStorage } from 'react-native';
import ImagePicker from 'react-native-image-crop-picker';
// Services and Actions
@ -105,21 +105,30 @@ class EditorContainer extends Component {
this.setState({ autoFocusText: true });
}
if (!isReply && !isEdit && !_draft) {
this._getDraft(username);
if (!isEdit && !_draft) {
this._getDraft(username, isReply);
}
}
_getDraft = (username) => {
getDraftPost(username)
.then((result) => {
this.setState({
draftPost: { body: result.body, title: result.title, tags: result.tags.split(',') },
});
})
.catch(() => {
// alert(error);
_getDraft = async (username, isReply) => {
if (isReply) {
const draftReply = await AsyncStorage.getItem('temp-reply');
this.setState({
draftPost: { body: draftReply },
});
} else {
await getDraftPost(username)
.then((result) => {
this.setState({
draftPost: { body: result.body, title: result.title, tags: result.tags.split(',') },
});
})
.catch(() => {
// alert(error);
});
}
};
_getPurePost = (author, permlink) => {
@ -264,8 +273,8 @@ class EditorContainer extends Component {
}
};
_saveCurrentDraft = (fields) => {
const { draftId } = this.state;
_saveCurrentDraft = async (fields) => {
const { draftId, isReply } = this.state;
if (!draftId) {
const { currentAccount } = this.props;
@ -276,7 +285,11 @@ class EditorContainer extends Component {
tags: fields.tags && fields.tags.length > 0 ? fields.tags.toString() : '',
};
setDraftPost(draftField, username);
if (isReply && draftField.body) {
await AsyncStorage.setItem('temp-reply', draftField.body);
} else {
setDraftPost(draftField, username);
}
}
};
@ -339,6 +352,8 @@ class EditorContainer extends Component {
},
key: permlink,
});
setDraftPost({ title: '', body: '', tags: [] }, currentAccount.name);
})
.catch((error) => {
this._handleSubmitFailure(error);

View File

@ -141,7 +141,7 @@ class EditorScreen extends Component {
handleFormChanged();
this._handleIsFormValid();
if (isReply) this._saveCurrentDraft();
this._saveCurrentDraft();
};
_handleOnTagAdded = (tags) => {

View File

@ -16,7 +16,7 @@ const authorNameRegex = /(^|[^a-zA-Z0-9_!#$%&*@\/]|(^|[^a-zA-Z0-9_+~.-\/]))[@
const tagsRegex = /(^|\s|>)(#[-a-z\d]+)/gi;
const centerRegex = /(<center>)/g;
const imgRegex = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|PNG|GIF|JPG))/g;
const linkRegex = /[-a-zA-Z0-9@:%+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%+.~#?&//=]*)?/gi;
const linkRegex = /[-a-zA-Z0-9@:%+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%+._~#?&//=]*)?/gi;
const markdownImageRegex = /!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g;
const urlRegex = /(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gm;
const aTagRegex = /(<\s*a[^>]*>(.*?)<\s*[/]\s*a>)/g;
@ -69,6 +69,10 @@ export const markDown2Html = (input) => {
output = handleIframe(output);
}
// if (imgRegex.test(output)) {
// output = handleImageLink(output);
// }
if (linkRegex.test(output)) {
output = handleLinks(output);
}
@ -160,7 +164,7 @@ const handleLinks = input => input.replace(linkRegex, (link) => {
if (imageMatch[0].indexOf('.gif') > 0) {
return gifBody(imageMatch[0]);
}
console.log(imageMatch);
if (imageMatch[0]) {
return imageBody(imageMatch[0]);
}
@ -169,7 +173,12 @@ const handleLinks = input => input.replace(linkRegex, (link) => {
}
return link;
} if (link.trim().indexOf('ipfs.busy.org') > 0) {
}
if (link.trim().indexOf('ipfs.busy.org') > 0) {
return imageBody(link);
}
if (imgRegex.test(link)) {
return imageBody(link);
}
}
@ -245,6 +254,8 @@ const createVimeoIframe = input => input.replace(vimeoRegex, (link) => {
return iframeBody(embedLink);
});
const handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
const iframeBody = link => `<iframe frameborder='0' allowfullscreen src='${link}'></iframe>`;
const imageBody = link => `<center style="text-align: center; align-items: center; justify-content: center;"><img src="${`https://steemitimages.com/600x0/${link}`}"></center>`;
const gifBody = link => `<img src="${`https://steemitimages.com/0x0/${link}`}">`;