Added tag search for search modal

This commit is contained in:
Mustafa Buyukcelebi 2019-02-22 09:49:41 +03:00
parent 3103fef132
commit cdc546b660
3 changed files with 29 additions and 18 deletions

View File

@ -41,17 +41,28 @@ class SearchModalContainer extends PureComponent {
if (text && text !== '@' && text !== '#') {
if (text[0] === '@') {
lookupAccounts(text.substr(1)).then((res) => {
const users = res.map(item => ({ author: item }));
const users = res.map(item => ({
image: `https://steemitimages.com/u/${item}/avatar/small`,
text: item,
}));
this.setState({ searchResults: { type: 'user', data: users } });
});
} else if (text[0] === '#') {
getTrendingTags(text.substr(1)).then((res) => {
console.log('res :', res);
// TODO:
const tags = res.map(item => ({
text: `#${item.name}`,
}));
this.setState({ searchResults: { type: 'tag', data: tags } });
});
} else {
search({ q: text }).then((res) => {
res.results = res.results.filter(item => item.title !== '');
res.results = res.results
.filter(item => item.title !== '')
.map(item => ({
image: item.img_url || `https://steemitimages.com/u/${item.author}/avatar/small`,
text: item.title,
}));
this.setState({ searchResults: { type: 'content', data: res.results } });
});
}

View File

@ -61,7 +61,7 @@ export default EStyleSheet.create({
borderColor: '$primaryGray',
},
searchItemText: {
color: '$primaryDarkGray',
color: '$white',
marginLeft: 10,
},
});

View File

@ -77,19 +77,19 @@ class SearchModalView extends PureComponent {
renderItem={({ item }) => (
<TouchableHighlight onPress={() => handleOnPressListItem(searchResults.type, item)}>
<View style={styles.searhItems}>
<FastImage
source={{
uri:
searchResults.type === 'user'
? `https://steemitimages.com/u/${item.author}/avatar/small`
: item.img_url
|| `https://steemitimages.com/u/${item.author}/avatar/small`,
}}
style={styles.searchItemImage}
/>
<Text style={styles.searchItemText}>
{searchResults.type === 'user' ? item.author : item.title}
</Text>
<View style={{ flex: 1 }}>
{item.image && (
<FastImage
source={{
uri: item.image,
}}
style={styles.searchItemImage}
/>
)}
</View>
<View style={{ flex: 7 }}>
{item.text && <Text style={styles.searchItemText}>{item.text}</Text>}
</View>
</View>
</TouchableHighlight>
)}