diff --git a/src/components/postDropdown/container/postDropdownContainer.js b/src/components/postDropdown/container/postDropdownContainer.js index 6ef1d6690..c2f7a07dc 100644 --- a/src/components/postDropdown/container/postDropdownContainer.js +++ b/src/components/postDropdown/container/postDropdownContainer.js @@ -121,7 +121,7 @@ class PostDropdownContainer extends PureComponent { /> (this.ActionSheet = o)} - options={['Reblog', intl.formatMessage({ id: 'post.reblog_cancel' })]} + options={['Reblog', intl.formatMessage({ id: 'alert.cancel' })]} title={intl.formatMessage({ id: 'post.reblog_alert' })} cancelButtonIndex={1} onPress={(index) => { diff --git a/src/components/postElements/headerDescription/view/postHeaderDescription.js b/src/components/postElements/headerDescription/view/postHeaderDescription.js index 292e6ced7..4ef8fc51d 100644 --- a/src/components/postElements/headerDescription/view/postHeaderDescription.js +++ b/src/components/postElements/headerDescription/view/postHeaderDescription.js @@ -2,8 +2,6 @@ import React, { PureComponent } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { withNavigation } from 'react-navigation'; -import FastImage from 'react-native-fast-image'; - // Components import { Tag, TextWithIcon } from '../../../basicUIElements'; import { UserAvatar } from '../../../userAvatar'; diff --git a/src/components/postListItem/view/postListItemStyles.js b/src/components/postListItem/view/postListItemStyles.js index cc2368da2..e5b03ca79 100644 --- a/src/components/postListItem/view/postListItemStyles.js +++ b/src/components/postListItem/view/postListItemStyles.js @@ -40,8 +40,8 @@ export default EStyleSheet.create({ color: '$primaryBlack', }, summary: { - fontSize: 16, - color: '$primaryDarkGray', + fontSize: 13, + color: '$primaryDarkText', }, header: { backgroundColor: '$primaryBackgroundColor', diff --git a/src/components/postListItem/view/postListItemView.js b/src/components/postListItem/view/postListItemView.js index 4fe71a00f..d87a221ec 100644 --- a/src/components/postListItem/view/postListItemView.js +++ b/src/components/postListItem/view/postListItemView.js @@ -1,13 +1,16 @@ -import React, { Component } from 'react'; +import React, { Component, Fragment } from 'react'; +import ActionSheet from 'react-native-actionsheet'; import { View, Text, TouchableOpacity } from 'react-native'; +import { injectIntl } from 'react-intl'; import FastImage from 'react-native-fast-image'; -import { PostHeaderDescription } from '../../postElements'; + +// Utils import { getTimeFromNow } from '../../../utils/time'; -// Constants - // Components +import { PostHeaderDescription } from '../../postElements'; import { IconButton } from '../../iconButton'; + // Defaults import DEFAULT_IMAGE from '../../../assets/no_image.png'; @@ -31,40 +34,66 @@ class PostListItemView extends Component { render() { const { - title, summary, mainTag, username, reputation, created, image, + title, + summary, + mainTag, + username, + reputation, + created, + image, + handleOnPressItem, + handleOnRemoveItem, + id, + intl, } = this.props; return ( - - - - + + + + + this.ActionSheet.show()} + style={[styles.rightItem]} + color="#c1c5c7" + /> + + + handleOnPressItem(id)}> + + + {title} + {summary} + + + - - - - - {title} - {summary} - - - - + (this.ActionSheet = o)} + options={[ + intl.formatMessage({ id: 'alert.delete' }), + intl.formatMessage({ id: 'alert.cancel' }), + ]} + title={intl.formatMessage({ id: 'alert.remove_alert' })} + cancelButtonIndex={1} + destructiveButtonIndex={0} + onPress={(index) => { + if (index === 0) handleOnRemoveItem(id); + }} + /> + ); } } -export default PostListItemView; +export default injectIntl(PostListItemView); diff --git a/src/components/transaction/container/transactionContainer.js b/src/components/transaction/container/transactionContainer.js index cf58a3a67..a6d1899b6 100644 --- a/src/components/transaction/container/transactionContainer.js +++ b/src/components/transaction/container/transactionContainer.js @@ -21,9 +21,9 @@ class TransactionContainer extends PureComponent { // Component Functions render() { - const { intl, walletData } = this.props; + const { walletData } = this.props; - return ; + return ; } } diff --git a/src/components/wallet/view/walletView.js b/src/components/wallet/view/walletView.js index 2f613f776..379ba566f 100644 --- a/src/components/wallet/view/walletView.js +++ b/src/components/wallet/view/walletView.js @@ -104,7 +104,7 @@ class WalletView extends PureComponent { > - + )} diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 86f317c3f..41a4d2817 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -132,11 +132,13 @@ "success_rebloged": "Rebloged!", "already_rebloged": "You have already reblogged!", "warning": "Warning", - "invalid_pincode": "Invalid pin code, please check and try again." + "invalid_pincode": "Invalid pin code, please check and try again.", + "remove_alert": "Are you sure want to remove?", + "cancel": "Cancel", + "delete": "Delete" }, "post": { - "reblog_alert": "Are you sure you want to reblog?", - "reblog_cancel": "Cancel" + "reblog_alert": "Are you sure you want to reblog?" }, "drafts": { "title": "Drafts", diff --git a/src/config/locales/ru-RU.json b/src/config/locales/ru-RU.json index 08627416b..fe69c734c 100644 --- a/src/config/locales/ru-RU.json +++ b/src/config/locales/ru-RU.json @@ -132,11 +132,13 @@ "success_rebloged": "Репостнуто!", "already_rebloged": "Вы уже делали этот репост!", "warning": "Внимание", - "invalid_pincode": "Не верный пин, пожалуйста, попробуйте снова." + "invalid_pincode": "Не верный пин, пожалуйста, попробуйте снова.", + "remove_alert": "Вы уверены, что хотите сделать Удалить?", + "cancel": "Отмена", + "delete": "Удалить" }, "post": { - "reblog_alert": "Вы уверены, что хотите сделать репост?", - "reblog_cancel": "Отмена" + "reblog_alert": "Вы уверены, что хотите сделать репост?" }, "gallery": { "title": "Галерея", diff --git a/src/config/locales/tr-TR.json b/src/config/locales/tr-TR.json index 39ead5359..d778c579e 100644 --- a/src/config/locales/tr-TR.json +++ b/src/config/locales/tr-TR.json @@ -133,11 +133,13 @@ "already_rebloged": "Zaten reblog yapmışsınız.", "failed_to_open": "Açılamadı.", "warning": "Uyarı!", - "invalid_pincode": "Geçersiz pin kod, lutfen tekrar deneyin." + "invalid_pincode": "Geçersiz pin kod, lutfen tekrar deneyin.", + "remove_alert": "Silmek istediginize emin misiniz?", + "cancel": "Vazgeç", + "delete": "Sil" }, "post": { - "reblog_alert": "Reblog yapma istediginize emin misiniz?", - "reblog_cancel": "Vazgeç" + "reblog_alert": "Reblog yapma istediginize emin misiniz?" }, // TODO: translate here!!! "drafts": { diff --git a/src/globalStyles.js b/src/globalStyles.js index 81b3262c3..3e8748e96 100644 --- a/src/globalStyles.js +++ b/src/globalStyles.js @@ -58,4 +58,11 @@ export default EStyleSheet.create({ marginLeft: 42, marginRight: 32, }, + hintText: { + color: '$iconColor', + alignSelf: 'center', + fontSize: 16, + marginLeft: 16, + fontWeight: '500', + }, }); diff --git a/src/screens/drafts/container/draftsContainer.js b/src/screens/drafts/container/draftsContainer.js index be7651cbf..891587998 100644 --- a/src/screens/drafts/container/draftsContainer.js +++ b/src/screens/drafts/container/draftsContainer.js @@ -9,6 +9,7 @@ import { getDrafts, removeDraft } from '../../../providers/esteem/esteem'; // Middleware // Constants +import { default as ROUTES } from '../../../constants/routeNames'; // Utilities @@ -52,27 +53,38 @@ class DraftsContainer extends Component { }); }; - _removeDraft = (selectedDraft) => { + _removeDraft = (id) => { const { currentAccount, intl } = this.props; - // getDrafts(currentAccount.name) - // .then((data) => { - // const { drafts } = this.state; - // const newDrafts = [...drafts].filter(draft => draft._id !== item._id); + removeDraft({ username: currentAccount.name, draftId: id }) + .then((data) => { + const { drafts } = this.state; + const newDrafts = [...drafts].filter(draft => draft._id !== id); - // Alert.alert(intl.formatMessage({ id: 'drafts.deleted' })); - // this.setState({ drafts: this.sortData(newDrafts) }); - // }) - // .catch(() => { - // Alert.alert(intl.formatMessage({ id: 'alert.fail' })); - // }) - // .finally(() => { - // this._getDrafts(); - // }); + // Alert.alert(intl.formatMessage({ id: 'drafts.deleted' })); + this.setState({ drafts: this._sortData(newDrafts) }); + }) + .catch(() => { + Alert.alert(intl.formatMessage({ id: 'alert.fail' })); + }); }; - _editDraft = () => { - alert('edit'); + _handleRemoveDraft = (id) => { + this._removeDraft(id); + }; + + _editDraft = (id) => { + const { navigation } = this.props; + const { drafts } = this.state; + const selectedDraft = drafts.find(draft => draft._id === id); + console.log(selectedDraft); + navigation.navigate({ + routeName: ROUTES.SCREENS.EDITOR, + params: { + draft: selectedDraft, + fetchPost: this._getDrafts, + }, + }); }; _sortData = data => data.sort((a, b) => { @@ -92,7 +104,7 @@ class DraftsContainer extends Component { editDraft={this._editDraft} currentAccount={currentAccount} drafts={drafts} - removeDraft={this._removeDraft} + removeDraft={this._handleRemoveDraft} /> ); } diff --git a/src/screens/drafts/screen/draftsScreen.js b/src/screens/drafts/screen/draftsScreen.js index 92a49522b..fd642bea7 100644 --- a/src/screens/drafts/screen/draftsScreen.js +++ b/src/screens/drafts/screen/draftsScreen.js @@ -4,12 +4,14 @@ import { View, FlatList, Text } from 'react-native'; // Utils import { getPostSummary } from '../../../utils/formatter'; - +import { catchDraftImage } from '../../../utils/image'; // Constants // Components import { BasicHeader } from '../../../components/basicHeader'; import { PostListItem } from '../../../components/postListItem'; +import { PostCardPlaceHolder } from '../../../components/basicUIElements'; + // Styles import globalStyles from '../../../globalStyles'; @@ -32,7 +34,7 @@ class DraftsScreen extends Component { const { currentAccount, removeDraft, editDraft } = this.props; const tags = item.tags ? item.tags.split(/[ ,]+/) : []; const tag = tags[0] || ''; - // const img = catchEntryImage(item) || noImage; + const image = catchDraftImage(item.body); const summary = getPostSummary(item.body, 100); return ( @@ -41,26 +43,39 @@ class DraftsScreen extends Component { mainTag={tag} title={item.title} summary={summary} + image={image ? { uri: catchDraftImage(item.body) } : null} username={currentAccount.name} reputation={currentAccount.reputation} handleOnPressItem={editDraft} handleOnRemoveItem={removeDraft} + id={item._id} /> ); }; render() { const { drafts, isLoading, intl } = this.props; + const isNoDrafts = drafts && drafts.length === 0; return ( - + + {isNoDrafts && ( + + {intl.formatMessage({ + id: 'drafts.empty_list', + })} + + )} {isLoading ? ( - Loading daa! + + + + ) : ( { return key.sign(new Buffer(array)).toString(); }; + +export const proxifyImageSrc = (url, width = 0, height = 0) => { + if (!url) { + return ''; + } + + const prefix = `https://steemitimages.com/${width}x${height}/`; + + if (url.startsWith(prefix)) return url; + + return `${prefix}${url}`; +}; + +export const catchEntryImage = (entry, width = 0, height = 0) => { + // return from json metadata if exists + let meta; + + try { + meta = JSON.parse(entry.json_metadata); + } catch (e) { + meta = null; + } + + if (meta && meta.image && meta.image.length > 0) { + if (meta.image[0]) { + return proxifyImageSrc(meta.image[0], width, height); + } + } + + // try to extract images by regex + const imgReg2 = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpe?g|gif|png)/gim; + const m = entry.body.match(imgReg2); + if (m) { + return proxifyImageSrc(m[0], width, height); + } + + // If no image specified in json metadata, try extract first image href from entry body + let imgReg = //; + let bodyMatch = entry.body.match(imgReg); + if (bodyMatch) { + return proxifyImageSrc(bodyMatch[1], width, height); + } + + // If there is no tag, check from markdown img tag ![](image.png) + imgReg = /(?:!\[(.*?)\]\((.*?)\))/; + bodyMatch = imgReg.exec(entry.body); + if (bodyMatch) { + return proxifyImageSrc(bodyMatch[2], width, height); + } + + return null; +}; + +export const catchDraftImage = (body) => { + const imgRegex = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|PNG|GIF|JPG))/g; + + if (imgRegex.test(body)) { + const imageMatch = body.match(imgRegex); + + return proxifyImageSrc(imageMatch[0]); + } + return null; +};