aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-04-09 09:46:55 -0700
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-04-09 10:08:10 -0700
commit0ebd64161da70d5d417886d7026ec8e0f4691db3 (patch)
treeabe620108af880a279d487d131e01e4bddf52d98 /src
parent84c103614247ab7dc8b86767f3bfa83c13f224aa (diff)
Changes for default suggested
Diffstat (limited to 'src')
-rw-r--r--src/screens/chat/ChatListScreen.tsx2
-rw-r--r--src/screens/chat/NewChatModal.tsx64
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()}