-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from UTDNebula/search-bar-submit
Search bar Submit functionality.
- Loading branch information
Showing
6 changed files
with
81 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
'use client'; | ||
import { type SelectUserMetadata } from '@src/server/db/models'; | ||
import { api } from '@src/trpc/react'; | ||
import { useState, useEffect } from 'react'; | ||
import { useState } from 'react'; | ||
import { DebouncedSearchBar } from './DebouncedSearchBar'; | ||
|
||
type UserSearchBarProps = { | ||
passUser: (user: { id: string; name: string }) => void; | ||
}; | ||
type User = { | ||
name: string; | ||
} & SelectUserMetadata; | ||
export const UserSearchBar = ({ passUser }: UserSearchBarProps) => { | ||
const [search, setSearch] = useState(''); | ||
const [res, setRes] = useState<User[]>([]); | ||
const userQuery = api.userMetadata.searchByName.useQuery( | ||
{ name: search }, | ||
{ | ||
enabled: !!search, | ||
}, | ||
); | ||
useEffect(() => { | ||
if (userQuery.data) { | ||
const newData = userQuery.data.map((val) => { | ||
const formattedData = userQuery.isSuccess | ||
? userQuery.data.map((val) => { | ||
return { name: val.firstName + ' ' + val.lastName, ...val }; | ||
}); | ||
setRes(newData); | ||
} | ||
}, [userQuery.data]); | ||
}) | ||
: []; | ||
return ( | ||
<DebouncedSearchBar | ||
placeholder="Search for Someone" | ||
setSearch={setSearch} | ||
value={search} | ||
searchResults={res} | ||
searchResults={formattedData} | ||
onClick={(user) => { | ||
passUser({ id: user.id, name: user.name }); | ||
setSearch(''); | ||
}} | ||
submitLogic={() => { | ||
if (formattedData && formattedData[0]) { | ||
const user = formattedData[0]; | ||
passUser({ id: user.id, name: user.name }); | ||
setSearch(''); | ||
} | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters