Merge pull request #1159 from esteemapp/feature/profile-edit

enhanced search added utils for avatar
This commit is contained in:
Mustafa Buyukcelebi 2019-09-18 15:15:19 +03:00 committed by GitHub
commit 5c8d189247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 64 deletions

View File

@ -6,6 +6,9 @@ import FastImage from 'react-native-fast-image';
import { TextInput } from '../../textInput'; import { TextInput } from '../../textInput';
import { Icon } from '../../icon'; import { Icon } from '../../icon';
// Utils
import { getResizedAvatar } from '../../../utils/image';
// Styles // Styles
import styles from './formInputStyles'; import styles from './formInputStyles';
@ -80,7 +83,7 @@ class FormInputView extends Component {
<FastImage <FastImage
style={styles.firstImage} style={styles.firstImage}
source={{ source={{
uri: `https://steemitimages.com/u/${value}/avatar/small`, uri: getResizedAvatar(value),
priority: FastImage.priority.high, priority: FastImage.priority.high,
}} }}
resizeMode={FastImage.resizeMode.cover} resizeMode={FastImage.resizeMode.cover}

View File

@ -1,17 +1,17 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import get from 'lodash/get';
// Services and Actions // Services and Actions
import { search } from '../../../providers/esteem/esteem'; import { search } from '../../../providers/esteem/esteem';
import { lookupAccounts, getTrendingTags } from '../../../providers/steem/dsteem'; import { lookupAccounts, getTrendingTags } from '../../../providers/steem/dsteem';
// Middleware
// Constants // Constants
import { default as ROUTES } from '../../../constants/routeNames'; import { default as ROUTES } from '../../../constants/routeNames';
// Utilities // Utilities
import { getResizedAvatar } from '../../../utils/image';
// Component // Component
import SearchModalView from '../view/searchModalView'; import SearchModalView from '../view/searchModalView';
@ -41,14 +41,17 @@ class SearchModalContainer extends PureComponent {
_handleOnChangeSearchInput = text => { _handleOnChangeSearchInput = text => {
const { isConnected } = this.props; const { isConnected } = this.props;
if (text && text.length < 2) return;
if (this.timer) {
clearTimeout(this.timer);
}
if (!isConnected) return; if (!isConnected) return;
this.timer = setTimeout(() => {
if (text && text !== '@' && text !== '#') { if (text && text !== '@' && text !== '#') {
if (text[0] === '@') { if (text[0] === '@') {
lookupAccounts(text.substr(1)).then(res => { lookupAccounts(text.substr(1)).then(res => {
const users = res.map(item => ({ const users = res.map(item => ({
image: `https://steemitimages.com/u/${item}/avatar/small`, image: getResizedAvatar(item),
text: item, text: item,
...item, ...item,
})); }));
@ -57,7 +60,7 @@ class SearchModalContainer extends PureComponent {
} else if (text[0] === '#') { } else if (text[0] === '#') {
getTrendingTags(text.substr(1)).then(res => { getTrendingTags(text.substr(1)).then(res => {
const tags = res.map(item => ({ const tags = res.map(item => ({
text: `#${item.name}`, text: `#${get(item, 'name', '')}`,
...item, ...item,
})); }));
@ -68,14 +71,15 @@ class SearchModalContainer extends PureComponent {
res.results = res.results res.results = res.results
.filter(item => item.title !== '') .filter(item => item.title !== '')
.map(item => ({ .map(item => ({
image: item.img_url || `https://steemitimages.com/u/${item.author}/avatar/small`, image: item.img_url || getResizedAvatar(get(item, 'author')),
text: item.title, text: item.title,
...item, ...item,
})); }));
this.setState({ searchResults: { type: 'content', data: res.results } }); this.setState({ searchResults: { type: 'content', data: get(res, 'results', []) } });
}); });
} }
} }
}, 500);
}; };
_handleOnPressListItem = (type, item) => { _handleOnPressListItem = (type, item) => {
@ -89,24 +93,24 @@ class SearchModalContainer extends PureComponent {
switch (type) { switch (type) {
case 'user': case 'user':
routeName = item.text === username ? ROUTES.TABBAR.PROFILE : ROUTES.SCREENS.PROFILE; routeName = get(item, 'text') === username ? ROUTES.TABBAR.PROFILE : ROUTES.SCREENS.PROFILE;
params = { params = {
username: item.text, username: get(item, 'text'),
}; };
key = item.text; key = item.text;
break; break;
case 'content': case 'content':
routeName = ROUTES.SCREENS.POST; routeName = ROUTES.SCREENS.POST;
params = { params = {
author: item.author, author: get(item, 'author'),
permlink: item.permlink, permlink: get(item, 'permlink'),
}; };
key = item.permlink; key = get(item, 'permlink');
break; break;
case 'tag': case 'tag':
routeName = ROUTES.SCREENS.SEARCH_RESULT; routeName = ROUTES.SCREENS.SEARCH_RESULT;
params = { params = {
tag: item.text.substr(1), tag: get(item, 'text', '').substr(1),
}; };
break; break;
@ -129,13 +133,13 @@ class SearchModalContainer extends PureComponent {
return ( return (
<SearchModalView <SearchModalView
searchResults={searchResults}
handleCloseButton={this._handleCloseButton} handleCloseButton={this._handleCloseButton}
handleOnChangeSearchInput={this._handleOnChangeSearchInput} handleOnChangeSearchInput={this._handleOnChangeSearchInput}
handleOnClose={handleOnClose}
handleOnPressListItem={this._handleOnPressListItem} handleOnPressListItem={this._handleOnPressListItem}
isOpen={isOpen} isOpen={isOpen}
handleOnClose={handleOnClose}
placeholder={placeholder} placeholder={placeholder}
searchResults={searchResults}
/> />
); );
} }

View File

@ -47,7 +47,7 @@ export default EStyleSheet.create({
marginRight: 24, marginRight: 24,
flex: 1, flex: 1,
}, },
searhItems: { searchItems: {
marginHorizontal: 30, marginHorizontal: 30,
marginVertical: 10, marginVertical: 10,
flexDirection: 'row', flexDirection: 'row',

View File

@ -1,9 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { View, Text, FlatList, TouchableOpacity, SafeAreaView } from 'react-native'; import { View, Text, FlatList, TouchableOpacity, SafeAreaView } from 'react-native';
import FastImage from 'react-native-fast-image'; import FastImage from 'react-native-fast-image';
import { get, has } from 'lodash';
// Constants
// Components // Components
import { Modal } from '../..'; import { Modal } from '../..';
@ -40,7 +38,7 @@ class SearchModalView extends PureComponent {
return ( return (
<Modal <Modal
isOpen={isOpen} isOpen={isOpen}
handleOnModalClose={() => handleOnClose()} handleOnModalClose={handleOnClose}
isFullScreen isFullScreen
swipeToClose swipeToClose
isTransparent isTransparent
@ -53,12 +51,14 @@ class SearchModalView extends PureComponent {
/> />
<View style={styles.body}> <View style={styles.body}>
<FlatList <FlatList
data={searchResults.data} data={get(searchResults, 'data', [])}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
renderItem={({ item }) => ( renderItem={({ item }) => (
// TODO: Make it quick ui component // TODO: Make it quick ui component
<TouchableOpacity onPress={() => handleOnPressListItem(searchResults.type, item)}> <TouchableOpacity
<View style={styles.searhItems}> onPress={() => handleOnPressListItem(get(searchResults, 'type'), item)}
>
<View style={styles.searchItems}>
<View style={styles.searchItemImageWrapper}> <View style={styles.searchItemImageWrapper}>
{item.image && ( {item.image && (
<FastImage <FastImage
@ -70,12 +70,12 @@ class SearchModalView extends PureComponent {
)} )}
</View> </View>
<View style={styles.searchItemTextWrapper}> <View style={styles.searchItemTextWrapper}>
{item.text && <Text style={styles.searchItemText}>{item.text}</Text>} {has(item, 'text') && <Text style={styles.searchItemText}>{item.text}</Text>}
</View> </View>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
)} )}
keyExtractor={(post, index) => index.toString()} keyExtractor={(item, index) => get(item, 'id', index).toString()}
removeClippedSubviews removeClippedSubviews
onEndThreshold={0} onEndThreshold={0}
initialNumToRender={20} initialNumToRender={20}

View File

@ -9,6 +9,9 @@ import styles from './userAvatarStyles';
// Constants // Constants
import ROUTES from '../../../constants/routeNames'; import ROUTES from '../../../constants/routeNames';
// Utils
import { getResizedAvatar } from '../../../utils/image';
const DEFAULT_IMAGE = require('../../../assets/avatar_default.png'); const DEFAULT_IMAGE = require('../../../assets/avatar_default.png');
/* Props /* Props
@ -58,11 +61,7 @@ class UserAvatarView extends Component {
let _size; let _size;
const _avatar = username const _avatar = username
? { ? {
uri: uri: avatarUrl || (name === username ? avatar : getResizedAvatar(username, imageSize)),
avatarUrl ||
(name === username
? avatar
: `https://steemitimages.com/u/${username}/avatar/${imageSize}`),
} }
: DEFAULT_IMAGE; : DEFAULT_IMAGE;

View File

@ -64,11 +64,16 @@ export const catchDraftImage = body => {
return null; return null;
}; };
export const getResizedImage = (url, size) => { export const getResizedImage = (url, size = 400) => {
if (!url) return ''; if (!url) return '';
const _size = size || 400;
if (url.includes('img.esteem')) return `https://img.esteem.ws/${_size}x0/${url}`; if (url.includes('img.esteem')) return `https://img.esteem.ws/${size}x0/${url}`;
return `https://steemitimages.com/${size}x0/${url}`; return `https://steemitimages.com/${size}x0/${url}`;
}; };
export const getResizedAvatar = (author, sizeString = 'small') => {
if (!author) return '';
return `https://steemitimages.com/u/${author}/avatar/${sizeString}`;
};

View File

@ -10,6 +10,7 @@ import { getPostReblogs } from '../providers/esteem/esteem';
// Utils // Utils
import { getReputation } from './reputation'; import { getReputation } from './reputation';
import { getResizedImage, getResizedAvatar } from './image';
export const parsePosts = async (posts, currentUserName) => { export const parsePosts = async (posts, currentUserName) => {
if (posts) { if (posts) {
@ -33,7 +34,7 @@ export const parsePost = async (post, currentUserName, isPromoted) => {
post.image = postImage(post.json_metadata, post.body); post.image = postImage(post.json_metadata, post.body);
post.vote_count = post.active_votes.length; post.vote_count = post.active_votes.length;
post.author_reputation = getReputation(post.author_reputation); post.author_reputation = getReputation(post.author_reputation);
post.avatar = `https://steemitimages.com/u/${post.author}/avatar/small`; post.avatar = getResizedAvatar(get(post, 'author'));
post.active_votes.sort((a, b) => b.rshares - a.rshares); post.active_votes.sort((a, b) => b.rshares - a.rshares);
post.body = renderPostBody(post); post.body = renderPostBody(post);
@ -89,7 +90,7 @@ const postImage = (metaData, body) => {
} }
if (imageLink) { if (imageLink) {
return `https://steemitimages.com/600x0/${imageLink}`; return getResizedImage(imageLink, 600);
} }
return ''; return '';
}; };
@ -108,7 +109,7 @@ export const parseComments = async (comments, currentUserName) => {
get(comment, 'pending_payout_value') ? get(comment, 'pending_payout_value') : 0, get(comment, 'pending_payout_value') ? get(comment, 'pending_payout_value') : 0,
).toFixed(3); ).toFixed(3);
comment.author_reputation = getReputation(get(comment, 'author_reputation')); comment.author_reputation = getReputation(get(comment, 'author_reputation'));
comment.avatar = `https://steemitimages.com/u/${get(comment, 'author')}/avatar/small`; comment.avatar = getResizedAvatar(get(comment, 'author'));
comment.markdownBody = get(comment, 'body'); comment.markdownBody = get(comment, 'body');
comment.body = renderPostBody(comment); comment.body = renderPostBody(comment);
comment.active_votes = activeVotes; comment.active_votes = activeVotes;
@ -170,7 +171,7 @@ const parseActiveVotes = (post, currentUserName) => {
value.reputation = getReputation(get(value, 'reputation')); value.reputation = getReputation(get(value, 'reputation'));
value.percent /= 100; value.percent /= 100;
value.is_down_vote = Math.sign(value.percent) < 0; value.is_down_vote = Math.sign(value.percent) < 0;
value.avatar = `https://steemitimages.com/u/${value.voter}/avatar/small`; value.avatar = getResizedAvatar(get(value, 'voter'));
}); });
} }