diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -16,7 +16,7 @@ import Animated from 'react-native-reanimated'; import { createSelector } from 'reselect'; -import { searchUsers } from 'lib/actions/user-actions.js'; +import { searchUsers as searchUsersEndpoint } from 'lib/actions/user-actions.js'; import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { type ChatThreadItem, @@ -30,7 +30,6 @@ getThreadListSearchResults, } from 'lib/shared/thread-utils.js'; import type { SetState } from 'lib/types/hook-types.js'; -import type { UserSearchResult } from 'lib/types/search-types.js'; import { threadTypes } from 'lib/types/thread-types-enum.js'; import type { ThreadInfo } from 'lib/types/thread-types.js'; import type { @@ -112,8 +111,6 @@ +indicatorStyle: IndicatorStyle, +usersWithPersonalThread: $ReadOnlySet, +navigateToThread: (params: MessageListParams) => void, - // async functions that hit server APIs - +searchUsers: (usernamePrefix: string) => Promise, +searchText: string, +setSearchText: SetState, +searchStatus: SearchStatus, @@ -129,6 +126,10 @@ +searchCancelButtonOpen: Value, +searchCancelButtonProgress: Node, +searchCancelButtonOffset: Node, + +searchUsers: ( + usernamePrefix: string, + ) => Promise<$ReadOnlyArray>, + +onChangeSearchText: (searchText: string) => Promise, }; class ChatThreadList extends React.PureComponent { @@ -255,7 +256,7 @@ }; onSearchCancel = () => { - this.onChangeSearchText(''); + this.props.onChangeSearchText(''); this.clearSearch(); }; @@ -285,7 +286,7 @@ - !this.props.usersWithPersonalThread.has(info.id) && - info.id !== this.props.loggedInUserInfo?.id, - ); - } - - onChangeSearchText = async (searchText: string) => { - const results = this.props.threadSearchIndex.getSearchResults(searchText); - this.props.setSearchText(searchText); - this.props.setThreadsSearchResults(new Set(results)); - this.props.setNumItemsToDisplay(25); - const usersSearchResults = await this.searchUsers(searchText); - this.props.setUsersSearchResults(usersSearchResults); - }; - onPressItem = ( threadInfo: ThreadInfo, pendingPersonalThreadUserInfo?: UserInfo, ) => { - this.onChangeSearchText(''); + this.props.onChangeSearchText(''); if (this.searchInput) { this.searchInput.blur(); } @@ -531,7 +510,7 @@ }; onPressSeeMoreSidebars = (threadInfo: ThreadInfo) => { - this.onChangeSearchText(''); + this.props.onChangeSearchText(''); if (this.searchInput) { this.searchInput.blur(); } @@ -606,7 +585,7 @@ const threadSearchIndex = useGlobalThreadSearchIndex(); const styles = useStyles(unboundStyles); const indicatorStyle = useSelector(indicatorStyleSelector); - const callSearchUsers = useServerCall(searchUsers); + const callSearchUsers = useServerCall(searchUsersEndpoint); const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector); const navigateToThread = useNavigateToThread(); @@ -642,6 +621,34 @@ [searchCancelButtonProgress], ); + const searchUsers = React.useCallback( + async (usernamePrefix: string) => { + if (usernamePrefix.length === 0) { + return []; + } + + const { userInfos } = await callSearchUsers(usernamePrefix); + return userInfos.filter( + info => + !usersWithPersonalThread.has(info.id) && + info.id !== loggedInUserInfo?.id, + ); + }, + [callSearchUsers, loggedInUserInfo?.id, usersWithPersonalThread], + ); + + const onChangeSearchText = React.useCallback( + async (updatedSearchText: string) => { + const results = threadSearchIndex.getSearchResults(updatedSearchText); + setSearchText(updatedSearchText); + setThreadsSearchResults(new Set(results)); + setNumItemsToDisplay(25); + const searchResults = await searchUsers(updatedSearchText); + setUsersSearchResults(searchResults); + }, + [searchUsers, threadSearchIndex], + ); + return ( ); }