diff --git a/src/screens/searchResult/container/postsResultsContainer.js b/src/screens/searchResult/container/postsResultsContainer.js index dfe9b4b05..2a1010c71 100644 --- a/src/screens/searchResult/container/postsResultsContainer.js +++ b/src/screens/searchResult/container/postsResultsContainer.js @@ -17,34 +17,40 @@ const PostsResultsContainer = ({ children, navigation, searchValue, currentAccou setData([]); if (searchValue) { - search({ q: searchValue, sort }).then((res) => { - setScrollId(res.scroll_id); - setData(res.results); - }); - } else { - getPromotePosts() - .then((result) => { - return Promise.all( - result.map((item) => - getPost( - get(item, 'author'), - get(item, 'permlink'), - currentAccountUsername, - true, - ).then((post) => { - post.author_rep = post.author_reputation; - post.body = (post.summary && post.summary.substring(0, 130)) || ''; - return post; - }), - ), - ); + search({ q: searchValue, sort }) + .then((res) => { + setScrollId(res.scroll_id); + setData(res.results); }) - .then((result) => { - setData(result); - }); + .catch((err) => console.log(err, 'search error')); + } else { + getInitialPosts().then((res) => { + console.log(res, 'res'); + // setData(res); + }); } }, [searchValue, sort]); + const getInitialPosts = async () => { + const promoteds = await getPromotePosts(); + + return await Promise.all( + promoteds.map(async (item) => { + const post = await getPost( + get(item, 'author'), + get(item, 'permlink'), + currentAccountUsername, + true, + ); + + post.author_rep = post.author_reputation; + post.body = (post.summary && post.summary.substring(0, 130)) || ''; + // return await call to your function + return post; + }), + ); + }; + // Component Functions const _handleOnPress = (item) => { diff --git a/src/screens/searchResult/container/topicsResultsContainer.js b/src/screens/searchResult/container/topicsResultsContainer.js index 190cdbafd..6c2e49d02 100644 --- a/src/screens/searchResult/container/topicsResultsContainer.js +++ b/src/screens/searchResult/container/topicsResultsContainer.js @@ -7,6 +7,7 @@ import ROUTES from '../../../constants/routeNames'; import { getTrendingTags } from '../../../providers/hive/dhive'; import { getLeaderboard } from '../../../providers/ecency/ecency'; +import { isCommunity } from '../../../utils/communityValidation'; const OtherResultContainer = (props) => { const [tags, setTags] = useState([]); @@ -17,7 +18,9 @@ const OtherResultContainer = (props) => { setTags([]); getTrendingTags(searchValue).then((res) => { - setTags(res); + const data = res.filter((item) => !isCommunity(item.name)); + console.log(data, 'data'); + setTags(data); }); }, [searchValue]); diff --git a/src/screens/searchResult/screen/searchResultScreen.js b/src/screens/searchResult/screen/searchResultScreen.js index 6a5552c45..11032f86b 100644 --- a/src/screens/searchResult/screen/searchResultScreen.js +++ b/src/screens/searchResult/screen/searchResultScreen.js @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { View, SafeAreaView } from 'react-native'; import ScrollableTabView from 'react-native-scrollable-tab-view'; import { useIntl } from 'react-intl'; +import { debounce } from 'lodash'; // Components import { SearchInput, TabBar } from '../../../components'; diff --git a/src/utils/communityValidation.js b/src/utils/communityValidation.js index 52ccf9f3e..11faf4e8f 100644 --- a/src/utils/communityValidation.js +++ b/src/utils/communityValidation.js @@ -1,5 +1,7 @@ +import { isNumber } from 'lodash'; + export const isCommunity = (text) => { - if (/^hive-\d+/.test(text) && text.length === 11) { + if (/^hive-\d+/.test(text) && text.length === 11 && isNumber(Number(text.split('-')[1]))) { return true; }