From ffaa7d3a65c3d03a5054cf0f9f8545aa4c5b9510 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Fri, 26 Apr 2019 15:32:02 +0300 Subject: [PATCH] Eslint fix --- .../postButton/view/postButtonView.js | 2 +- .../postButton/view/postButtonsForAndroid.js | 2 +- .../view/postHeaderDescription.js | 2 +- src/realm/realm.js | 2 +- .../container/applicationContainer.js | 2 +- .../application/screen/applicationScreen.js | 4 +- src/screens/drafts/screen/draftsScreen.js | 10 +- .../pinCode/container/pinCodeContainer.js | 2 +- src/utils/editor.js | 10 +- src/utils/markdownToHtml.js | 324 +++++++++--------- src/utils/postParser.js | 22 +- src/utils/sendEmail.js | 16 +- 12 files changed, 193 insertions(+), 205 deletions(-) diff --git a/src/components/postButton/view/postButtonView.js b/src/components/postButton/view/postButtonView.js index adf4d2da9..ce168fed8 100644 --- a/src/components/postButton/view/postButtonView.js +++ b/src/components/postButton/view/postButtonView.js @@ -38,7 +38,7 @@ class PostButtonView extends Component { if (this.mode._value) { const { routes, isCollapsePostButtonOpen } = this.props; const nextRouteName = nextProps.routes[0].routes[nextProps.routes[0].routes.length - 1].routeName; - const routeName = routes[0].routes[routes[0].routes.length - 1].routeName; + const { routeName } = routes[0].routes[routes[0].routes.length - 1]; const { isCollapse } = this.state; if ( diff --git a/src/components/postButton/view/postButtonsForAndroid.js b/src/components/postButton/view/postButtonsForAndroid.js index 35b26fdf9..e47df80a1 100644 --- a/src/components/postButton/view/postButtonsForAndroid.js +++ b/src/components/postButton/view/postButtonsForAndroid.js @@ -35,7 +35,7 @@ class PostButtonsForAndroid extends Component { // For closing sub buttons const { routes, isCollapsePostButtonOpen } = this.props; const nextRouteName = nextProps.routes[0].routes[nextProps.routes[0].routes.length - 1].routeName; - const routeName = routes[0].routes[routes[0].routes.length - 1].routeName; + const { routeName } = routes[0].routes[routes[0].routes.length - 1]; const { isCollapse } = this.state; if ( diff --git a/src/components/postElements/headerDescription/view/postHeaderDescription.js b/src/components/postElements/headerDescription/view/postHeaderDescription.js index 6d6849a47..8aa64b526 100644 --- a/src/components/postElements/headerDescription/view/postHeaderDescription.js +++ b/src/components/postElements/headerDescription/view/postHeaderDescription.js @@ -32,7 +32,7 @@ class PostHeaderDescription extends PureComponent { } // Component Functions - _handleOnUserPress = username => { + _handleOnUserPress = (username) => { const { navigation, profileOnPress, reputation } = this.props; if (profileOnPress) { diff --git a/src/realm/realm.js b/src/realm/realm.js index 037cf6de7..6104bb7b5 100644 --- a/src/realm/realm.js +++ b/src/realm/realm.js @@ -189,7 +189,7 @@ export const updateUserData = userData => new Promise((resolve, reject) => { export const removeUserData = username => new Promise((resolve, reject) => { try { - const account = realm.objects(USER_SCHEMA).filtered('username = $0', username) + const account = realm.objects(USER_SCHEMA).filtered('username = $0', username); if (Array.from(account).length > 0) { realm.write(() => { realm.delete(account); diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index e4940deef..4114e1a5f 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -175,7 +175,7 @@ class ApplicationContainer extends Component { await getAuthStatus().then((res) => { ({ currentUsername } = res); - + if (res) { getUserData().then(async (userData) => { if (userData.length > 0) { diff --git a/src/screens/application/screen/applicationScreen.js b/src/screens/application/screen/applicationScreen.js index 51d73d885..6415103d6 100644 --- a/src/screens/application/screen/applicationScreen.js +++ b/src/screens/application/screen/applicationScreen.js @@ -42,7 +42,9 @@ class ApplicationScreen extends Component { }; render() { - const { isConnected, isDarkTheme, locale, toastNotification } = this.props; + const { + isConnected, isDarkTheme, locale, toastNotification, + } = this.props; const { isShowToastNotification } = this.state; const barStyle = isDarkTheme ? 'light-content' : 'dark-content'; const barColor = isDarkTheme ? '#1e2835' : '#fff'; diff --git a/src/screens/drafts/screen/draftsScreen.js b/src/screens/drafts/screen/draftsScreen.js index 7b81adc85..eff9f5721 100644 --- a/src/screens/drafts/screen/draftsScreen.js +++ b/src/screens/drafts/screen/draftsScreen.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { injectIntl } from 'react-intl'; import { View, FlatList, Text } from 'react-native'; import ScrollableTabView from '@esteemapp/react-native-scrollable-tab-view'; +import ActionSheet from 'react-native-actionsheet'; // Utils import { getPostSummary } from '../../../utils/formatter'; @@ -13,7 +14,6 @@ import { BasicHeader } from '../../../components/basicHeader'; import { PostListItem } from '../../../components/postListItem'; import { PostCardPlaceHolder } from '../../../components/basicUIElements'; import { TabBar } from '../../../components/tabBar'; -import ActionSheet from 'react-native-actionsheet'; // Styles import globalStyles from '../../../globalStyles'; @@ -29,7 +29,7 @@ class DraftsScreen extends Component { super(props); this.state = { selectedId: null, - } + }; } // Component Life Cycles @@ -56,7 +56,7 @@ class DraftsScreen extends Component { image={image ? { uri: catchDraftImage(item.body) } : null} username={currentAccount.name} reputation={currentAccount.reputation} - handleOnPressItem={() => isSchedules ? this.setState({selectedId: item._id}, () => this.ActionSheet.show()) : editDraft} + handleOnPressItem={() => (isSchedules ? this.setState({ selectedId: item._id }, () => this.ActionSheet.show()) : editDraft)} handleOnRemoveItem={isSchedules ? removeSchedule : removeDraft} id={item._id} key={item._id} @@ -97,7 +97,9 @@ class DraftsScreen extends Component { }; render() { - const { drafts, schedules, intl, moveScheduleToDraft } = this.props; + const { + drafts, schedules, intl, moveScheduleToDraft, + } = this.props; const { selectedId } = this.state; return ( diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index e8275a3fb..8fd9eab9d 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -286,7 +286,7 @@ class PinCodeContainer extends Component { [ { text: intl.formatMessage({ id: 'alert.clear' }), onPress: () => this._forgotPinCode() }, { text: intl.formatMessage({ id: 'alert.cancel' }), style: 'destructive' }, - ] + ], ); }; diff --git a/src/utils/editor.js b/src/utils/editor.js index 8899ab02e..851213626 100644 --- a/src/utils/editor.js +++ b/src/utils/editor.js @@ -84,11 +84,11 @@ export const makeJsonMetadataReply = tags => ({ }); export const makeJsonMetadata = (meta, tags) => Object.assign({}, meta, { - tags, - app: 'esteem/2.0.0-mobile', - format: 'markdown+html', - community: 'esteem.app', - }); + tags, + app: 'esteem/2.0.0-mobile', + format: 'markdown+html', + community: 'esteem.app', +}); export const extractMetadata = (body) => { const urlReg = /(\b(https?|ftp):\/\/[A-Z0-9+&@#/%?=~_|!:,.;-]*[-A-Z0-9+&@#/%=~_|])/gim; diff --git a/src/utils/markdownToHtml.js b/src/utils/markdownToHtml.js index a66b09ebf..539ba2f8a 100644 --- a/src/utils/markdownToHtml.js +++ b/src/utils/markdownToHtml.js @@ -24,7 +24,7 @@ const imgTagRegex = /(]*>)/g; const iframeRegex = /(?:]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/g; const hTagRegex = /(([^<]*)<\/h([1-6])>)/g; -export const markDown2Html = input => { +export const markDown2Html = (input) => { if (!input) { return ''; } @@ -95,192 +95,178 @@ export const markDown2Html = input => { return output; }; -const replaceAuthorNames = input => - input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => { - const userLower = user.toLowerCase(); - const preceedings = (preceeding1 || '') + (preceeding2 || ''); - return `${preceedings} @${user}`; - }); +const replaceAuthorNames = input => input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => { + const userLower = user.toLowerCase(); + const preceedings = (preceeding1 || '') + (preceeding2 || ''); + return `${preceedings} @${user}`; +}); -const replaceTags = input => - input.replace(tagsRegex, tag => { - if (/#[\d]+$/.test(tag)) return tag; - const preceding = /^\s|>/.test(tag) ? tag[0] : ''; - tag = tag.replace('>', ''); - const tag2 = tag.trim().substring(1); - const tagLower = tag2.toLowerCase(); - return `${preceding}${tag.trim()}`; - }); +const replaceTags = input => input.replace(tagsRegex, (tag) => { + if (/#[\d]+$/.test(tag)) return tag; + const preceding = /^\s|>/.test(tag) ? tag[0] : ''; + tag = tag.replace('>', ''); + const tag2 = tag.trim().substring(1); + const tagLower = tag2.toLowerCase(); + return `${preceding}${tag.trim()}`; +}); -const handleATag = input => - input.replace(aTagRegex, link => { - if (dTubeRegex.test(link)) { - const dTubeMatch = link.match(dTubeRegex)[0]; - const execLink = dTubeRegex.exec(dTubeMatch); +const handleATag = input => input.replace(aTagRegex, (link) => { + if (dTubeRegex.test(link)) { + const dTubeMatch = link.match(dTubeRegex)[0]; + const execLink = dTubeRegex.exec(dTubeMatch); - if (execLink[2] && execLink[3]) { - const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`; - - return iframeBody(embedLink); - } - if (dTubeMatch) { - return iframeBody(dTubeMatch); - } - return link; - } - - if (imgRegex.test(link)) { - const imgMatch = link.match(imgRegex)[0]; - - if (imgMatch) return `Image`; - } - - return link; - }); - -const handleHTag = input => input.replace(hTagRegex, tag => `
${tag}
`); - -const handleMarkdownLink = input => - input.replace(copiedPostRegex, link => { - const postMatch = link.match(copiedPostRegex); - - if (postMatch) { - let tag = postMatch[1]; - - if (tag === '/busy.org') { - tag = 'busy'; - } - - const _permlink = - postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3]; - - return `/${_permlink}`; - } - }); - -const handleLinks = input => - input.replace(linkRegex, link => { - if (link) { - if ( - link - .toLowerCase() - .trim() - .indexOf('https://steemitimages.com/0x0/') === 0 || - imgRegex.test(link) - ) { - const imageMatch = link.match(imgRegex); - - if (imageMatch) { - if (imageMatch[0].indexOf('.gif') > 0) { - return gifBody(imageMatch[0]); - } - - if (imageMatch[0]) { - return imageBody(imageMatch[0]); - } - } else if (link.trim().indexOf('ipfs.busy.org') > 0) { - return imageBody(link); - } - - return link; - } - if (link.trim().indexOf('ipfs.busy.org') > 0) { - return imageBody(link); - } - - if (imgRegex.test(link)) { - return imageBody(link); - } - } - - return link; - }); - -const changeMarkdownImage = input => - input.replace(markdownImageRegex, link => { - const markdownMatch = link.match(markdownImageRegex); - if (markdownMatch[0]) { - const firstMarkdownMatch = markdownMatch[0]; - const _link = firstMarkdownMatch.match(urlRegex)[0]; - - return _link; - } - return link; - }); - -const centerStyling = input => - input.replace( - centerRegex, - () => '
', - ); - -const steemitUrlHandle = input => - input.replace(postRegex, link => { - const postMatch = link.match(postRegex); - const tag = postMatch[2]; - const author = postMatch[3].replace('@', ''); - const permlink = postMatch[4]; - - return `/${permlink}`; - }); - -const handleImageTag = input => - input.replace(imgTagRegex, imgTag => { - const _imgTag = imgTag.trim(); - const match = _imgTag.match(imgRegex); - - if (match && match[0]) { - return match[0]; - } - - return imgTag; - }); - -const createYoutubeIframe = input => - input.replace(youTubeRegex, link => { - if (link.indexOf(')') || link.indexOf('(')) { - return link; - } - - const execVideo = youTubeRegex.exec(link); - const match = link.match(youTubeRegex); - - if (execVideo[1] && match) { - const videoLink = execVideo[1]; - const embedLink = `https://www.youtube.com/embed/${videoLink}`; + if (execLink[2] && execLink[3]) { + const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`; return iframeBody(embedLink); } - + if (dTubeMatch) { + return iframeBody(dTubeMatch); + } return link; - }); + } -const handleIframe = input => - input.replace(iframeRegex, link => { - const match = link.match(linkRegex); + if (imgRegex.test(link)) { + const imgMatch = link.match(imgRegex)[0]; - if (match && match[0]) { - return iframeBody(match[0]); + if (imgMatch) return `Image`; + } + + return link; +}); + +const handleHTag = input => input.replace(hTagRegex, tag => `
${tag}
`); + +const handleMarkdownLink = input => input.replace(copiedPostRegex, (link) => { + const postMatch = link.match(copiedPostRegex); + + if (postMatch) { + let tag = postMatch[1]; + + if (tag === '/busy.org') { + tag = 'busy'; } + const _permlink = postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3]; + + return `/${_permlink}`; + } +}); + +const handleLinks = input => input.replace(linkRegex, (link) => { + if (link) { + if ( + link + .toLowerCase() + .trim() + .indexOf('https://steemitimages.com/0x0/') === 0 + || imgRegex.test(link) + ) { + const imageMatch = link.match(imgRegex); + + if (imageMatch) { + if (imageMatch[0].indexOf('.gif') > 0) { + return gifBody(imageMatch[0]); + } + + if (imageMatch[0]) { + return imageBody(imageMatch[0]); + } + } else if (link.trim().indexOf('ipfs.busy.org') > 0) { + return imageBody(link); + } + + return link; + } + if (link.trim().indexOf('ipfs.busy.org') > 0) { + return imageBody(link); + } + + if (imgRegex.test(link)) { + return imageBody(link); + } + } + + return link; +}); + +const changeMarkdownImage = input => input.replace(markdownImageRegex, (link) => { + const markdownMatch = link.match(markdownImageRegex); + if (markdownMatch[0]) { + const firstMarkdownMatch = markdownMatch[0]; + const _link = firstMarkdownMatch.match(urlRegex)[0]; + + return _link; + } + return link; +}); + +const centerStyling = input => input.replace( + centerRegex, + () => '
', +); + +const steemitUrlHandle = input => input.replace(postRegex, (link) => { + const postMatch = link.match(postRegex); + const tag = postMatch[2]; + const author = postMatch[3].replace('@', ''); + const permlink = postMatch[4]; + + return `/${permlink}`; +}); + +const handleImageTag = input => input.replace(imgTagRegex, (imgTag) => { + const _imgTag = imgTag.trim(); + const match = _imgTag.match(imgRegex); + + if (match && match[0]) { + return match[0]; + } + + return imgTag; +}); + +const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => { + if (link.indexOf(')') || link.indexOf('(')) { return link; - }); + } -const createVimeoIframe = input => - input.replace(vimeoRegex, link => { - const execLink = vimeoRegex.exec(link); + const execVideo = youTubeRegex.exec(link); + const match = link.match(youTubeRegex); - const embedLink = `https://player.vimeo.com/video/${execLink[3]}`; + if (execVideo[1] && match) { + const videoLink = execVideo[1]; + const embedLink = `https://www.youtube.com/embed/${videoLink}`; return iframeBody(embedLink); - }); + } + + return link; +}); + +const handleIframe = input => input.replace(iframeRegex, (link) => { + const match = link.match(linkRegex); + + if (match && match[0]) { + return iframeBody(match[0]); + } + + return link; +}); + +const createVimeoIframe = input => input.replace(vimeoRegex, (link) => { + const execLink = vimeoRegex.exec(link); + + const embedLink = `https://player.vimeo.com/video/${execLink[3]}`; + + return iframeBody(embedLink); +}); const iframeBody = link => ``; -const imageBody = link => - `
`; +const imageBody = link => `
`; const gifBody = link => ``; const handleImageLink = input => input.replace(imgRegex, link => imageBody(link)); diff --git a/src/utils/postParser.js b/src/utils/postParser.js index 93994b639..9f297c799 100644 --- a/src/utils/postParser.js +++ b/src/utils/postParser.js @@ -3,8 +3,9 @@ import { markDown2Html } from './markdownToHtml'; import { getPostSummary } from './formatter'; 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) => { if (!post) { @@ -32,10 +33,9 @@ export const parsePost = (post, currentUserName) => { post.is_voted = false; } - const totalPayout = - parseFloat(post.pending_payout_value) + - parseFloat(post.total_payout_value) + - parseFloat(post.curator_payout_value); + const totalPayout = parseFloat(post.pending_payout_value) + + parseFloat(post.total_payout_value) + + parseFloat(post.curator_payout_value); post.total_payout = totalPayout.toFixed(3); @@ -44,8 +44,7 @@ export const parsePost = (post, currentUserName) => { if (post.active_votes && post.active_votes.length > 0) { 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].reputation = getReputation(post.active_votes[i].reputation); post.active_votes[i].percent = post.active_votes[i].percent / 100; @@ -59,8 +58,7 @@ export const parsePost = (post, currentUserName) => { 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 imgTagRegex = /(]*>)/g; @@ -135,8 +133,8 @@ const postImage = (metaData, body) => { // } // }; -export const parseComments = comments => { - comments.map(comment => { +export const parseComments = (comments) => { + comments.map((comment) => { comment.pending_payout_value = parseFloat(comment.pending_payout_value).toFixed(3); comment.vote_count = comment.active_votes.length; comment.author_reputation = getReputation(comment.author_reputation); diff --git a/src/utils/sendEmail.js b/src/utils/sendEmail.js index ca8538a68..4a3359b40 100644 --- a/src/utils/sendEmail.js +++ b/src/utils/sendEmail.js @@ -1,27 +1,27 @@ import { Linking } from 'react-native'; import qs from 'qs'; - export const sendEmail = async (to, subject, body, options = {}) => { +export const sendEmail = async (to, subject, body, options = {}) => { const { cc, bcc } = options; - let url = `mailto:${to}`; + let url = `mailto:${to}`; - const query = qs.stringify({ + const query = qs.stringify({ subject, body, cc, bcc, }); - if (query.length) { + if (query.length) { url += `?${query}`; } - const canOpen = await Linking.canOpenURL(url); + const canOpen = await Linking.canOpenURL(url); - if (!canOpen) { + if (!canOpen) { throw new Error('Provided URL can not be handled'); } - return Linking.openURL(url); -}; \ No newline at end of file + return Linking.openURL(url); +};