Page MenuHomePhabricator

D6478.id21674.diff
No OneTemporary

D6478.id21674.diff

diff --git a/lib/hooks/child-threads.js b/lib/hooks/child-threads.js
--- a/lib/hooks/child-threads.js
+++ b/lib/hooks/child-threads.js
@@ -10,7 +10,7 @@
useFilteredChatListData,
type ChatThreadItem,
} from '../selectors/chat-selectors';
-import { threadSearchIndex } from '../selectors/nav-selectors';
+import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors';
import { childThreadInfos } from '../selectors/thread-selectors';
import { threadInChatList } from '../shared/thread-utils';
import threadWatcher from '../shared/thread-watcher';
@@ -45,7 +45,7 @@
);
const allSubchannelsList = useFilteredChatListData(filterSubchannels);
- const searchIndex = useSelector(threadSearchIndex);
+ const searchIndex = useGlobalThreadSearchIndex();
const searchResultIDs = React.useMemo(
() => searchIndex.getSearchResults(searchText),
diff --git a/lib/selectors/nav-selectors.js b/lib/selectors/nav-selectors.js
--- a/lib/selectors/nav-selectors.js
+++ b/lib/selectors/nav-selectors.js
@@ -11,8 +11,8 @@
import type { BaseNavInfo } from '../types/nav-types';
import type { BaseAppState } from '../types/redux-types';
import type { RawThreadInfo, ThreadInfo } from '../types/thread-types';
-import type { UserInfos } from '../types/user-types';
import { getConfig } from '../utils/config';
+import { values } from '../utils/objects';
import { useSelector } from '../utils/redux-utils';
function timeUntilCalendarRangeExpiration(
@@ -86,32 +86,17 @@
}, [threadInfos, userInfos, viewerID]);
}
-const threadSearchIndex: (
- state: BaseAppState<*>,
-) => SearchIndex = createSelector(
- (state: BaseAppState<*>) => state.threadStore.threadInfos,
- (state: BaseAppState<*>) => state.userStore.userInfos,
- (state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id,
- (
- threadInfos: { +[id: string]: RawThreadInfo },
- userInfos: UserInfos,
- viewerID: ?string,
- ) => {
- const searchIndex = new SearchIndex();
- for (const threadID in threadInfos) {
- const thread = threadInfos[threadID];
- searchIndex.addEntry(
- threadID,
- threadSearchText(thread, userInfos, viewerID),
- );
- }
- return searchIndex;
- },
-);
+function useGlobalThreadSearchIndex(): SearchIndex {
+ const threadInfos = useSelector(state => state.threadStore.threadInfos);
+ const threadInfosArray = React.useMemo(() => values(threadInfos), [
+ threadInfos,
+ ]);
+ return useThreadSearchIndex(threadInfosArray);
+}
export {
timeUntilCalendarRangeExpiration,
currentCalendarQuery,
- threadSearchIndex,
useThreadSearchIndex,
+ useGlobalThreadSearchIndex,
};
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -27,7 +27,7 @@
ChatThreadItem,
ChatMessageInfoItem,
} from '../selectors/chat-selectors';
-import { threadSearchIndex as threadSearchIndexSelector } from '../selectors/nav-selectors';
+import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors';
import {
threadInfoSelector,
pendingToRealizedThreadIDsSelector,
@@ -1296,7 +1296,7 @@
new Set(),
);
const [usersSearchResults, setUsersSearchResults] = React.useState([]);
- const threadSearchIndex = useSelector(threadSearchIndexSelector);
+ const threadSearchIndex = useGlobalThreadSearchIndex();
React.useEffect(() => {
(async () => {
const results = threadSearchIndex.getSearchResults(searchText);
@@ -1419,7 +1419,6 @@
pendingThreadIDRegex,
parsePendingThreadID,
createPendingThread,
- createPendingThreadItem,
createPendingSidebar,
pendingThreadType,
createRealThreadFromPendingThread,
diff --git a/native/calendar/thread-picker-modal.react.js b/native/calendar/thread-picker-modal.react.js
--- a/native/calendar/thread-picker-modal.react.js
+++ b/native/calendar/thread-picker-modal.react.js
@@ -9,7 +9,7 @@
createLocalEntry,
createLocalEntryActionType,
} from 'lib/actions/entry-actions';
-import { threadSearchIndex } from 'lib/selectors/nav-selectors';
+import { useGlobalThreadSearchIndex } from 'lib/selectors/nav-selectors';
import { onScreenEntryEditableThreadInfos } from 'lib/selectors/thread-selectors';
import Modal from '../components/modal.react';
@@ -72,7 +72,7 @@
[navigation, rootNavigatorContext],
);
- const index = useSelector(state => threadSearchIndex(state));
+ const index = useGlobalThreadSearchIndex();
const onScreenThreadInfos = useSelector(state =>
onScreenEntryEditableThreadInfos(state),
);
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
@@ -21,7 +21,7 @@
type ChatThreadItem,
useFlattenedChatListData,
} from 'lib/selectors/chat-selectors';
-import { threadSearchIndex as threadSearchIndexSelector } from 'lib/selectors/nav-selectors';
+import { useGlobalThreadSearchIndex } from 'lib/selectors/nav-selectors';
import { usersWithPersonalThreadSelector } from 'lib/selectors/user-selectors';
import SearchIndex from 'lib/shared/search-index';
import {
@@ -618,7 +618,7 @@
const viewerID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
);
- const threadSearchIndex = useSelector(threadSearchIndexSelector);
+ const threadSearchIndex = useGlobalThreadSearchIndex();
const styles = useStyles(unboundStyles);
const indicatorStyle = useSelector(indicatorStyleSelector);
const callSearchUsers = useServerCall(searchUsers);
diff --git a/web/modals/threads/thread-picker-modal.react.js b/web/modals/threads/thread-picker-modal.react.js
--- a/web/modals/threads/thread-picker-modal.react.js
+++ b/web/modals/threads/thread-picker-modal.react.js
@@ -4,7 +4,7 @@
import * as React from 'react';
import { createSelector } from 'reselect';
-import { threadSearchIndex } from 'lib/selectors/nav-selectors';
+import { useGlobalThreadSearchIndex } from 'lib/selectors/nav-selectors';
import { onScreenEntryEditableThreadInfos } from 'lib/selectors/thread-selectors';
import type { ThreadInfo } from 'lib/types/thread-types';
@@ -57,7 +57,7 @@
const { createNewEntry, ...modalProps } = props;
const onScreenThreadInfos = useSelector(onScreenEntryEditableThreadInfos);
- const searchIndex = useSelector(state => threadSearchIndex(state));
+ const searchIndex = useGlobalThreadSearchIndex();
invariant(
onScreenThreadInfos.length > 0,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 4:36 AM (18 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690169
Default Alt Text
D6478.id21674.diff (6 KB)

Event Timeline