Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3378401
D4056.id12744.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D4056.id12744.diff
View Options
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
@@ -3,6 +3,8 @@
import * as React from 'react';
import { sidebarInfoSelector } from '../selectors/thread-selectors';
+import SearchIndex from '../shared/search-index';
+import { threadSearchText } from '../shared/thread-utils';
import type { SetState } from '../types/hook-types';
import type { SidebarInfo, ThreadInfo } from '../types/thread-types';
import { useSelector } from '../utils/redux-utils';
@@ -18,12 +20,15 @@
listData: $ReadOnlyArray<SidebarInfo>,
searchState: SidebarSearchState,
setSearchState: SetState<SidebarSearchState>,
+ searchIndex: SearchIndex,
} {
const [searchState, setSearchState] = React.useState({
text: '',
results: new Set<string>(),
});
+ const userInfos = useSelector(state => state.userStore.userInfos);
+
const sidebarInfos = useSelector(
state => sidebarInfoSelector(state)[threadInfo.id] ?? [],
);
@@ -37,11 +42,32 @@
);
}, [sidebarInfos, searchState]);
- return React.useMemo(() => ({ listData, searchState, setSearchState }), [
- listData,
- setSearchState,
- searchState,
- ]);
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
+ const searchIndex = React.useMemo(() => {
+ const index = new SearchIndex();
+ for (const sidebarInfo of sidebarInfos) {
+ const threadInfoFromSidebarInfo = sidebarInfo.threadInfo;
+ index.addEntry(
+ threadInfoFromSidebarInfo.id,
+ threadSearchText(threadInfoFromSidebarInfo, userInfos, viewerID),
+ );
+ }
+ return index;
+ }, [sidebarInfos, userInfos, viewerID]);
+
+ React.useEffect(() => {
+ setSearchState(curState => ({
+ ...curState,
+ results: new Set(searchIndex.getSearchResults(curState.text)),
+ }));
+ }, [searchIndex, setSearchState]);
+
+ return React.useMemo(
+ () => ({ listData, searchState, setSearchState, searchIndex }),
+ [listData, setSearchState, searchState, searchIndex],
+ );
}
export { useSearchSidebars };
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
@@ -4,16 +4,12 @@
import { TextInput, FlatList, StyleSheet } from 'react-native';
import { useSearchSidebars } from 'lib/hooks/search-sidebars';
-import { sidebarInfoSelector } from 'lib/selectors/thread-selectors';
-import SearchIndex from 'lib/shared/search-index';
-import { threadSearchText } from 'lib/shared/thread-utils';
import type { ThreadInfo, SidebarInfo } from 'lib/types/thread-types';
import Modal from '../components/modal.react';
import Search from '../components/search.react';
import type { RootNavigationProp } from '../navigation/root-navigator.react';
import type { NavigationRoute } from '../navigation/route-names';
-import { useSelector } from '../redux/redux-utils';
import { useIndicatorStyle } from '../themes/colors';
import { waitForModalInputFocus } from '../utils/timers';
import { useNavigateToThread } from './message-list-types';
@@ -35,35 +31,12 @@
+route: NavigationRoute<'SidebarListModal'>,
};
function SidebarListModal(props: Props): React.Node {
- const threadID = props.route.params.threadInfo.id;
- const { listData, searchState, setSearchState } = useSearchSidebars(
- props.route.params.threadInfo,
- );
- const sidebarInfos = useSelector(
- state => sidebarInfoSelector(state)[threadID] ?? [],
- );
-
- const userInfos = useSelector(state => state.userStore.userInfos);
- const viewerID = useSelector(
- state => state.currentUserInfo && state.currentUserInfo.id,
- );
- const searchIndex = React.useMemo(() => {
- const index = new SearchIndex();
- for (const sidebarInfo of sidebarInfos) {
- const { threadInfo } = sidebarInfo;
- index.addEntry(
- threadInfo.id,
- threadSearchText(threadInfo, userInfos, viewerID),
- );
- }
- return index;
- }, [sidebarInfos, userInfos, viewerID]);
- React.useEffect(() => {
- setSearchState(curState => ({
- ...curState,
- results: new Set(searchIndex.getSearchResults(curState.text)),
- }));
- }, [searchIndex, setSearchState]);
+ const {
+ listData,
+ searchState,
+ setSearchState,
+ searchIndex,
+ } = useSearchSidebars(props.route.params.threadInfo);
const onChangeSearchText = React.useCallback(
(searchText: string) =>
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
@@ -6,14 +6,10 @@
import * as React from 'react';
import { useSearchSidebars } from 'lib/hooks/search-sidebars';
-import { sidebarInfoSelector } from 'lib/selectors/thread-selectors';
-import SearchIndex from 'lib/shared/search-index';
-import { threadSearchText } from 'lib/shared/thread-utils';
import type { ThreadInfo } from 'lib/types/thread-types';
import chatThreadListCSS from '../../chat/chat-thread-list.css';
import SidebarItem from '../../chat/sidebar-item.react';
-import { useSelector } from '../../redux/redux-utils';
import globalCSS from '../../style.css';
import { MagnifyingGlass } from '../../vectors.react';
import Input from '../input.react';
@@ -26,16 +22,14 @@
function SidebarListModal(props: Props): React.Node {
const { threadInfo } = props;
- const { listData, searchState, setSearchState } = useSearchSidebars(
- threadInfo,
- );
+ const {
+ listData,
+ searchState,
+ setSearchState,
+ searchIndex,
+ } = useSearchSidebars(threadInfo);
const { popModal } = useModalContext();
- const sidebarInfos = useSelector(
- state => sidebarInfoSelector(state)[threadInfo.id] ?? [],
- );
- const userInfos = useSelector(state => state.userStore.userInfos);
-
const sidebars = React.useMemo(
() =>
listData.map(item => (
@@ -53,28 +47,6 @@
[popModal, listData],
);
- const viewerID = useSelector(
- state => state.currentUserInfo && state.currentUserInfo.id,
- );
- const searchIndex = React.useMemo(() => {
- const index = new SearchIndex();
- for (const sidebarInfo of sidebarInfos) {
- const threadInfoFromSidebarInfo = sidebarInfo.threadInfo;
- index.addEntry(
- threadInfoFromSidebarInfo.id,
- threadSearchText(threadInfoFromSidebarInfo, userInfos, viewerID),
- );
- }
- return index;
- }, [sidebarInfos, userInfos, viewerID]);
-
- React.useEffect(() => {
- setSearchState(curState => ({
- ...curState,
- results: new Set(searchIndex.getSearchResults(curState.text)),
- }));
- }, [searchIndex, setSearchState]);
-
const onChangeSearchText = React.useCallback(
(event: SyntheticEvent<HTMLInputElement>) => {
const searchText = event.currentTarget.value;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 10:14 AM (18 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593747
Default Alt Text
D4056.id12744.diff (6 KB)
Attached To
Mode
D4056: [native, web, lib] [refactor] [ENG-536] move search index to hook
Attached
Detach File
Event Timeline
Log In to Comment