From 77481b4ac48d8a05b01b2e3f8b4435e6ca513201 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Fri, 18 Oct 2024 16:52:46 -0500 Subject: [PATCH] Fixed search. Now request relationship is next hurdle --- components/home/RequestRelationship.tsx | 6 +++++- constants/APIs.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/home/RequestRelationship.tsx b/components/home/RequestRelationship.tsx index abe7c19..2242d54 100644 --- a/components/home/RequestRelationship.tsx +++ b/components/home/RequestRelationship.tsx @@ -37,9 +37,13 @@ const RequestRelationship: setSearchResults([]); return; } + const user = await getUser() as User; setIsLoading(true); - const users: User[] = await searchUsers(encodeURIComponent(term)) as User[]; + console.log(user.id, encodeURIComponent(term)); + const users: User[] = await searchUsers(user.id, encodeURIComponent(term)) as User[]; + console.log(users); setSearchResults(users); + setIsLoading(false); }, 300), []); const handleSearch = async (text: string) => { diff --git a/constants/APIs.ts b/constants/APIs.ts index 9e2720b..19c5375 100644 --- a/constants/APIs.ts +++ b/constants/APIs.ts @@ -114,7 +114,7 @@ export const checkRelationshipStatus = async (userId: number) => { const relationshipData = await response.json() as RelationshipData; return relationshipData; } catch (error: unknown) { - console.log('Error checking relationship status:', error); + //console.log('Error checking relationship status:', error); throw error; } }; @@ -146,10 +146,10 @@ export const updateRelationshipStatus = async (userId: number, status: 'accepted } }; -export const searchUsers = async (searchTerm: string) => { +export const searchUsers = async (userId: number, searchTerm: string) => { try { const apiUrl = `${process.env.EXPO_PUBLIC_API_URL}/api/users/search`; - const response = await fetch((apiUrl + `?searchTerm=${searchTerm}`), { + const response = await fetch((apiUrl + `?userId=${userId}&searchTerm=${searchTerm}`), { headers: { 'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '', },