Fixed community search bug

This commit is contained in:
Mustafa Buyukcelebi 2020-07-19 19:25:12 +03:00
parent 0f0210d8c2
commit 84b8e6ebf1
4 changed files with 23 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import { useState, useEffect } from 'react';
import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux';
import isEmpty from 'lodash/isEmpty';
import ROUTES from '../../../constants/routeNames';
@ -20,12 +21,16 @@ const CommunitiesContainer = ({
const [query, setQuery] = useState('');
const [sort, setSort] = useState('rank');
const [allSubscriptions, setAllSubscriptions] = useState([]);
const [noResult, setNoResult] = useState(false);
useEffect(() => {
setData([]);
getCommunities('', 100, query, sort).then((res) => {
if (res) {
if (!isEmpty(res)) {
setData(res);
setNoResult(false);
} else {
setNoResult(true);
}
});
}, [query, sort]);
@ -33,6 +38,7 @@ const CommunitiesContainer = ({
useEffect(() => {
setData([]);
setQuery(searchValue);
setNoResult(false);
}, [searchValue]);
useEffect(() => {
@ -74,6 +80,7 @@ const CommunitiesContainer = ({
handleOnPress: _handleOnPress,
handleSubscribeButtonPress: _handleSubscribeButtonPress,
isLoggedIn,
noResult,
})
);
};

View File

@ -25,6 +25,7 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
handleOnPress,
handleSubscribeButtonPress,
isLoggedIn,
noResult,
}) => (
<>
<FilterBar
@ -46,6 +47,7 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
handleOnPress={handleOnPress}
handleSubscribeButtonPress={handleSubscribeButtonPress}
isLoggedIn={isLoggedIn}
noResult={noResult}
/>
</>
)}

View File

@ -14,6 +14,7 @@ const VotersDisplayView = ({
handleSubscribeButtonPress,
allSubscriptions,
isLoggedIn,
noResult,
}) => {
const _renderItem = (item, index) => {
const isSubscribed = allSubscriptions.some((sub) => sub[0] === item.name);
@ -54,12 +55,14 @@ const VotersDisplayView = ({
return (
<SafeAreaView style={styles.container}>
<FlatList
data={votes}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item, index }) => _renderItem(item, index)}
ListEmptyComponent={_renderEmptyContent}
/>
{!noResult && (
<FlatList
data={votes}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item, index }) => _renderItem(item, index)}
ListEmptyComponent={_renderEmptyContent}
/>
)}
</SafeAreaView>
);
};

View File

@ -1,6 +1,7 @@
import React from 'react';
import { SafeAreaView, FlatList, View, Text, TouchableOpacity } from 'react-native';
import get from 'lodash/get';
import isUndefined from 'lodash/isUndefined';
import FastImage from 'react-native-fast-image';
import { useIntl } from 'react-intl';
@ -38,7 +39,9 @@ const PostResult = ({ navigation, searchValue }) => {
</Text>
</View>
<View style={styles.stats}>
{item.payout && <Text style={styles.postIconText}>{`$ ${item.payout}`}</Text>}
{!isUndefined(item.payout) && (
<Text style={styles.postIconText}>{`$ ${item.payout}`}</Text>
)}
<TextWithIcon
iconName="heart-outline"
textStyle={styles.postIconText}