fixed comment bug

This commit is contained in:
u-e 2019-03-23 15:50:42 +03:00
parent 8b38141c61
commit fb5a1a6d27
3 changed files with 32 additions and 18 deletions

View File

@ -90,10 +90,14 @@ class EditorContainer extends Component {
this.setState( this.setState(
{ {
isEdit, isEdit,
draftPost: { title: post.title, body: post.markdownBody, tags: post.json_metadata.tags }, draftPost: {
title: post.title,
body: post.markdownBody,
tags: post.json_metadata.tags,
},
}, },
() => { () => {
this._getPurePost(post.author, post.permlink); // this._getPurePost(post.author, post.permlink);
}, },
); );
} }
@ -293,8 +297,8 @@ class EditorContainer extends Component {
_submitPost = async (fields) => { _submitPost = async (fields) => {
const { const {
navigation, currentAccount, pinCode, intl, isDefaultFooter, navigation, currentAccount, pinCode, intl, isDefaultFooter
} = this.props; } = this.props;
if (currentAccount) { if (currentAccount) {
this.setState({ isPostSending: true }); this.setState({ isPostSending: true });
@ -411,14 +415,19 @@ class EditorContainer extends Component {
} = post; } = post;
let newBody = fields.body; let newBody = fields.body;
let _oldMeta = oldMeta;
const patch = createPatch(oldBody, newBody.trim()); const patch = createPatch(oldBody, newBody.trim());
if (patch && patch.length < Buffer.from(oldBody, 'utf-8').length) { if (patch && patch.length < Buffer.from(oldBody, 'utf-8').length) {
newBody = patch; newBody = patch;
} }
if (typeof _oldMeta === 'string') {
_oldMeta = JSON.parse(_oldMeta);
}
const meta = extractMetadata(fields.body); const meta = extractMetadata(fields.body);
const metadata = Object.assign({}, oldMeta, meta); const metadata = Object.assign({}, _oldMeta, meta);
const jsonMeta = makeJsonMetadata(metadata, fields.tags); const jsonMeta = makeJsonMetadata(metadata, fields.tags);
await postContent( await postContent(

View File

@ -88,7 +88,7 @@ export const makeJsonMetadata = (meta, tags) => Object.assign({}, meta, {
app: 'esteem/2.0.0-mobile', app: 'esteem/2.0.0-mobile',
format: 'markdown+html', format: 'markdown+html',
community: 'esteem.app', community: 'esteem.app',
}); });
export const extractMetadata = (body) => { export const extractMetadata = (body) => {
const urlReg = /(\b(https?|ftp):\/\/[A-Z0-9+&@#/%?=~_|!:,.;-]*[-A-Z0-9+&@#/%=~_|])/gim; const urlReg = /(\b(https?|ftp):\/\/[A-Z0-9+&@#/%?=~_|!:,.;-]*[-A-Z0-9+&@#/%=~_|])/gim;

View File

@ -3,7 +3,8 @@ import { markDown2Html } from './markdownToHtml';
import { getPostSummary } from './formatter'; import { getPostSummary } from './formatter';
import { getReputation } from './reputation'; import { getReputation } from './reputation';
export const parsePosts = (posts, currentUserName) => (!posts ? null : posts.map(post => parsePost(post, currentUserName))); export const parsePosts = (posts, currentUserName) =>
!posts ? null : posts.map(post => parsePost(post, currentUserName));
export const parsePost = (post, currentUserName) => { export const parsePost = (post, currentUserName) => {
if (!post) { if (!post) {
@ -31,9 +32,10 @@ export const parsePost = (post, currentUserName) => {
post.is_voted = false; post.is_voted = false;
} }
const totalPayout = parseFloat(post.pending_payout_value) const totalPayout =
+ parseFloat(post.total_payout_value) parseFloat(post.pending_payout_value) +
+ parseFloat(post.curator_payout_value); parseFloat(post.total_payout_value) +
parseFloat(post.curator_payout_value);
post.total_payout = totalPayout.toFixed(3); post.total_payout = totalPayout.toFixed(3);
@ -42,7 +44,8 @@ export const parsePost = (post, currentUserName) => {
if (post.active_votes && post.active_votes.length > 0) { if (post.active_votes && post.active_votes.length > 0) {
for (const i in post.active_votes) { for (const i in post.active_votes) {
post.vote_perecent = post.active_votes[i].voter === currentUserName ? post.active_votes[i].percent : null; post.vote_perecent =
post.active_votes[i].voter === currentUserName ? post.active_votes[i].percent : null;
post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(3); post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(3);
post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation);
post.active_votes[i].percent = post.active_votes[i].percent / 100; post.active_votes[i].percent = post.active_votes[i].percent / 100;
@ -56,7 +59,8 @@ export const parsePost = (post, currentUserName) => {
return post; return post;
}; };
const isVoted = (activeVotes, currentUserName) => activeVotes.some(v => v.voter === currentUserName && v.percent > 0); const isVoted = (activeVotes, currentUserName) =>
activeVotes.some(v => v.voter === currentUserName && v.percent > 0);
const postImage = (metaData, body) => { const postImage = (metaData, body) => {
const imgTagRegex = /(<img[^>]*>)/g; const imgTagRegex = /(<img[^>]*>)/g;
@ -131,12 +135,13 @@ const postImage = (metaData, body) => {
// } // }
// }; // };
export const parseComments = (comments) => { export const parseComments = comments => {
comments.map((comment) => { comments.map(comment => {
comment.pending_payout_value = parseFloat(comment.pending_payout_value).toFixed(3); comment.pending_payout_value = parseFloat(comment.pending_payout_value).toFixed(3);
comment.vote_count = comment.active_votes.length; comment.vote_count = comment.active_votes.length;
comment.author_reputation = getReputation(comment.author_reputation); comment.author_reputation = getReputation(comment.author_reputation);
comment.avatar = `https://steemitimages.com/u/${comment.author}/avatar/small`; comment.avatar = `https://steemitimages.com/u/${comment.author}/avatar/small`;
comment.markdownBody = comment.body;
comment.body = markDown2Html(comment.body); comment.body = markDown2Html(comment.body);
comment.summary = getPostSummary(comment.body, 100, true); comment.summary = getPostSummary(comment.body, 100, true);
}); });