From 0ebd64161da70d5d417886d7026ec8e0f4691db3 Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Fri, 9 Apr 2021 09:46:55 -0700 Subject: Changes for default suggested --- src/screens/chat/ChatListScreen.tsx | 2 +- src/screens/chat/NewChatModal.tsx | 64 +++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index ca1461fe..daea9984 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -98,7 +98,7 @@ const ChatListScreen: React.FC = ({navigation}) => { )} - {modalVisible && } + diff --git a/src/screens/chat/NewChatModal.tsx b/src/screens/chat/NewChatModal.tsx index 2bbaf8d2..32a9b667 100644 --- a/src/screens/chat/NewChatModal.tsx +++ b/src/screens/chat/NewChatModal.tsx @@ -16,13 +16,14 @@ import {ScreenType} from '../../types'; import {normalize} from '../../utils'; import {ChatResultsList, ChatSearchBar} from './index'; interface NewChatModalProps { + modalVisible: boolean; setChatModalVisible: (open: boolean) => void; } -const NewChatModal: React.FC = ({setChatModalVisible}) => { - const [modalVisible, setModalVisible] = useState(true); - const navigation = useNavigation(); - const sheetRef = useRef(null); +const NewChatModal: React.FC = ({ + modalVisible, + setChatModalVisible, +}) => { const [searching, setSearching] = useState(false); /* * Animated value @@ -40,29 +41,51 @@ const NewChatModal: React.FC = ({setChatModalVisible}) => { setSearching(false); }; + const getDefaultSuggested = async () => { + const searchResults = await loadSearchResults( + `${SEARCH_ENDPOINT}?query=&requestType=suggested`, + ); + console.log(searchResults); + const sanitizedResult = [ + { + title: 'users', + data: searchResults?.users, + }, + ]; + console.log(searchResults, sanitizedResult); + setResults(sanitizedResult); + }; + + const getQuerySuggested = async () => { + const searchResults = await loadSearchResults( + `${SEARCH_ENDPOINT}?query=${query}&requestType='search'`, + ); + if (query.length > 2) { + const sanitizedResult = [ + { + title: 'users', + data: searchResults?.users, + }, + ]; + setResults(sanitizedResult); + } else { + setResults([]); + } + }; + useEffect(() => { + if (query.length === 0) { + getDefaultSuggested(); + } + if (!searching) { return; } + if (query.length < 3) { return; } - (async () => { - const searchResults = await loadSearchResults( - `${SEARCH_ENDPOINT}?query=${query}`, - ); - if (query.length > 2) { - const sanitizedResult = [ - { - title: 'users', - data: searchResults?.users, - }, - ]; - setResults(sanitizedResult); - } else { - setResults([]); - } - })(); + getQuerySuggested(); }, [query]); const _modalContent = () => { @@ -100,7 +123,6 @@ const NewChatModal: React.FC = ({setChatModalVisible}) => { {_modalContent()} -- cgit v1.2.3-70-g09d2