diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/screens/chat/ChatListScreen.tsx | 2 | ||||
-rw-r--r-- | src/screens/chat/NewChatModal.tsx | 64 |
2 files changed, 44 insertions, 22 deletions
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<ChatListScreenProps> = ({navigation}) => { </View> </Chat> )} - {modalVisible && <NewChatModal {...{setChatModalVisible}} />} + <NewChatModal {...{modalVisible, setChatModalVisible}} /> </SafeAreaView> <TabsGradient /> </View> 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<NewChatModalProps> = ({setChatModalVisible}) => { - const [modalVisible, setModalVisible] = useState(true); - const navigation = useNavigation(); - const sheetRef = useRef(null); +const NewChatModal: React.FC<NewChatModalProps> = ({ + modalVisible, + setChatModalVisible, +}) => { const [searching, setSearching] = useState(false); /* * Animated value @@ -40,29 +41,51 @@ const NewChatModal: React.FC<NewChatModalProps> = ({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<NewChatModalProps> = ({setChatModalVisible}) => { <BottomDrawer initialSnapPosition={'90%'} isOpen={modalVisible} - enabledContentGestureInteraction={true} setIsOpen={setChatModalVisible} showHeader={false}> {_modalContent()} |