Page MenuHomePhabricator

D4057.id12824.diff
No OneTemporary

D4057.id12824.diff

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,9 @@
+listData: $ReadOnlyArray<SidebarInfo>,
+searchState: SidebarSearchState,
+setSearchState: SetState<SidebarSearchState>,
- +searchIndex: SearchIndex,
+ +onChangeSearchText: (
+ text: SyntheticEvent<HTMLInputElement> | string,
+ ) => mixed,
} {
const [searchState, setSearchState] = React.useState({
text: '',
@@ -57,6 +59,23 @@
return index;
}, [sidebarInfos, userInfos, viewerID]);
+ const onChangeSearchText = React.useCallback(
+ (event: SyntheticEvent<HTMLInputElement> | string) => {
+ let text;
+ if (typeof event === 'string') {
+ text = event;
+ } else {
+ text = event.currentTarget.value;
+ }
+
+ setSearchState({
+ text,
+ results: new Set(searchIndex.getSearchResults(text)),
+ });
+ },
+ [searchIndex, setSearchState],
+ );
+
React.useEffect(() => {
setSearchState(curState => ({
...curState,
@@ -65,8 +84,13 @@
}, [searchIndex, setSearchState]);
return React.useMemo(
- () => ({ listData, searchState, setSearchState, searchIndex }),
- [listData, setSearchState, searchState, searchIndex],
+ () => ({
+ listData,
+ searchState,
+ setSearchState,
+ onChangeSearchText,
+ }),
+ [listData, setSearchState, searchState, onChangeSearchText],
);
}
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,
+ onChangeSearchText,
} = 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<typeof TextInput>) => {
diff --git a/web/modals/chat/sidebar-list-modal.react.js b/web/modals/chat/sidebar-list-modal.react.js
--- a/web/modals/chat/sidebar-list-modal.react.js
+++ b/web/modals/chat/sidebar-list-modal.react.js
@@ -26,7 +26,7 @@
listData,
searchState,
setSearchState,
- searchIndex,
+ onChangeSearchText,
} = useSearchSidebars(threadInfo);
const { popModal } = useModalContext();
@@ -47,17 +47,6 @@
[popModal, listData],
);
- const onChangeSearchText = React.useCallback(
- (event: SyntheticEvent<HTMLInputElement>) => {
- const searchText = event.currentTarget.value;
- setSearchState({
- text: searchText,
- results: new Set(searchIndex.getSearchResults(searchText)),
- });
- },
- [searchIndex, setSearchState],
- );
-
const clearQuery = React.useCallback(
(event: SyntheticEvent<HTMLAnchorElement>) => {
event.preventDefault();

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 11:05 AM (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2611448
Default Alt Text
D4057.id12824.diff (3 KB)

Event Timeline