diff --git a/lib/hooks/search-sidebars.js b/lib/hooks/search-sidebars.js --- a/lib/hooks/search-sidebars.js +++ b/lib/hooks/search-sidebars.js @@ -20,7 +20,7 @@ +listData: $ReadOnlyArray, +searchState: SidebarSearchState, +setSearchState: SetState, - +searchIndex: SearchIndex, + +onChangeSearchInputText: (text: string) => mixed, } { const [searchState, setSearchState] = React.useState({ text: '', @@ -57,6 +57,16 @@ return index; }, [sidebarInfos, userInfos, viewerID]); + const onChangeSearchInputText = React.useCallback( + (text: string) => { + setSearchState({ + text, + results: new Set(searchIndex.getSearchResults(text)), + }); + }, + [searchIndex, setSearchState], + ); + React.useEffect(() => { setSearchState(curState => ({ ...curState, @@ -65,8 +75,13 @@ }, [searchIndex, setSearchState]); return React.useMemo( - () => ({ listData, searchState, setSearchState, searchIndex }), - [listData, setSearchState, searchState, searchIndex], + () => ({ + listData, + searchState, + setSearchState, + onChangeSearchInputText, + }), + [listData, setSearchState, searchState, onChangeSearchInputText], ); } diff --git a/native/chat/sidebar-list-modal.react.js b/native/chat/sidebar-list-modal.react.js --- a/native/chat/sidebar-list-modal.react.js +++ b/native/chat/sidebar-list-modal.react.js @@ -35,18 +35,9 @@ listData, searchState, setSearchState, - searchIndex, + onChangeSearchInputText, } = useSearchSidebars(props.route.params.threadInfo); - const onChangeSearchText = React.useCallback( - (searchText: string) => - setSearchState({ - text: searchText, - results: new Set(searchIndex.getSearchResults(searchText)), - }), - [searchIndex, setSearchState], - ); - const searchTextInputRef = React.useRef(); const setSearchTextInputRef = React.useCallback( async (textInput: ?React.ElementRef) => { @@ -95,7 +86,7 @@ ) => { - const searchText = event.currentTarget.value; - setSearchState({ - text: searchText, - results: new Set(searchIndex.getSearchResults(searchText)), - }); - }, - [searchIndex, setSearchState], - ); - const clearQuery = React.useCallback( (event: SyntheticEvent) => { event.preventDefault(); @@ -78,6 +67,14 @@ ); } + const handleOnChangeSearchText = React.useCallback( + (event: SyntheticEvent) => { + const { value } = event.currentTarget; + onChangeSearchInputText(value); + }, + [onChangeSearchInputText], + ); + return (
{clearQueryButton}