Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3325302
D13902.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D13902.id.diff
View Options
diff --git a/lib/components/global-search-index-provider.react.js b/lib/components/global-search-index-provider.react.js
new file mode 100644
--- /dev/null
+++ b/lib/components/global-search-index-provider.react.js
@@ -0,0 +1,42 @@
+// @flow
+
+import invariant from 'invariant';
+import * as React from 'react';
+
+import { useThreadSearchIndex } from '../selectors/nav-selectors.js';
+import SearchIndex from '../shared/search-index.js';
+import { values } from '../utils/objects.js';
+import { useSelector } from '../utils/redux-utils.js';
+
+type GlobalSearchIndexContextType = {
+ +searchIndex: SearchIndex,
+};
+
+const GlobalSearchIndexContext: React.Context<?GlobalSearchIndexContextType> =
+ React.createContext();
+
+type Props = {
+ +children: React.Node,
+};
+function GlobalSearchIndexProvider(props: Props): React.Node {
+ const threadInfos = useSelector(state => state.threadStore.threadInfos);
+ const threadInfosArray = React.useMemo(
+ () => values(threadInfos),
+ [threadInfos],
+ );
+ const searchIndex = useThreadSearchIndex(threadInfosArray);
+ const context = React.useMemo(() => ({ searchIndex }), [searchIndex]);
+ return (
+ <GlobalSearchIndexContext.Provider value={context}>
+ {props.children}
+ </GlobalSearchIndexContext.Provider>
+ );
+}
+
+function useGlobalThreadSearchIndex(): SearchIndex {
+ const globalSearchIndexContext = React.useContext(GlobalSearchIndexContext);
+ invariant(globalSearchIndexContext, 'globalSearchIndexContext should be set');
+ return globalSearchIndexContext.searchIndex;
+}
+
+export { GlobalSearchIndexProvider, useGlobalThreadSearchIndex };
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
@@ -6,11 +6,11 @@
fetchSingleMostRecentMessagesFromThreadsActionTypes,
useFetchSingleMostRecentMessagesFromThreads,
} from '../actions/message-actions.js';
+import { useGlobalThreadSearchIndex } from '../components/global-search-index-provider.react.js';
import {
type ChatThreadItem,
useFilteredChatListData,
} from '../selectors/chat-selectors.js';
-import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors.js';
import { childThreadInfos } from '../selectors/thread-selectors.js';
import { useThreadsInChatList } from '../shared/thread-utils.js';
import threadWatcher from '../shared/thread-watcher.js';
diff --git a/lib/hooks/thread-search-hooks.js b/lib/hooks/thread-search-hooks.js
--- a/lib/hooks/thread-search-hooks.js
+++ b/lib/hooks/thread-search-hooks.js
@@ -4,8 +4,8 @@
import { useUsersSupportThickThreads } from './user-identities-hooks.js';
import { searchUsers as searchUserCall } from '../actions/user-actions.js';
+import { useGlobalThreadSearchIndex } from '../components/global-search-index-provider.react.js';
import { useLegacyAshoatKeyserverCall } from '../keyserver-conn/legacy-keyserver-call.js';
-import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors.js';
import { usersWithPersonalThreadSelector } from '../selectors/user-selectors.js';
import {
useForwardLookupSearchText,
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
@@ -21,7 +21,6 @@
import { threadTypeIsPrivate } from '../types/thread-types-enum.js';
import type { UserInfo } from '../types/user-types.js';
import { getConfig } from '../utils/config.js';
-import { values } from '../utils/objects.js';
import { useSelector } from '../utils/redux-utils.js';
function timeUntilCalendarRangeExpiration(
@@ -192,19 +191,9 @@
}, [threadInfos, viewerID, userInfos, memberMap]);
}
-function useGlobalThreadSearchIndex(): SearchIndex {
- const threadInfos = useSelector(state => state.threadStore.threadInfos);
- const threadInfosArray = React.useMemo(
- () => values(threadInfos),
- [threadInfos],
- );
- return useThreadSearchIndex(threadInfosArray);
-}
-
export {
timeUntilCalendarRangeExpiration,
currentCalendarQuery,
useUserSearchIndex,
useThreadSearchIndex,
- useGlobalThreadSearchIndex,
};
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
@@ -8,7 +8,7 @@
createLocalEntry,
createLocalEntryActionType,
} from 'lib/actions/entry-actions.js';
-import { useGlobalThreadSearchIndex } from 'lib/selectors/nav-selectors.js';
+import { useGlobalThreadSearchIndex } from 'lib/components/global-search-index-provider.react.js';
import { useOnScreenEntryEditableThreadInfos } from 'lib/shared/thread-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -27,6 +27,7 @@
import { EditUserAvatarProvider } from 'lib/components/edit-user-avatar-provider.react.js';
import { ENSCacheProvider } from 'lib/components/ens-cache-provider.react.js';
import { FarcasterDataHandler } from 'lib/components/farcaster-data-handler.react.js';
+import { GlobalSearchIndexProvider } from 'lib/components/global-search-index-provider.react.js';
import IntegrityHandler from 'lib/components/integrity-handler.react.js';
import { MediaCacheProvider } from 'lib/components/media-cache-provider.react.js';
import { NeynarClientProvider } from 'lib/components/neynar-client-provider.react.js';
@@ -313,9 +314,11 @@
<ChatContextProvider>
<DeepLinksContextProvider>
<ChatMentionContextProvider>
- <NUXTipsContextProvider>
- <RootNavigator />
- </NUXTipsContextProvider>
+ <GlobalSearchIndexProvider>
+ <NUXTipsContextProvider>
+ <RootNavigator />
+ </NUXTipsContextProvider>
+ </GlobalSearchIndexProvider>
</ChatMentionContextProvider>
</DeepLinksContextProvider>
</ChatContextProvider>
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -16,6 +16,7 @@
import { ChatMentionContextProvider } from 'lib/components/chat-mention-provider.react.js';
import { EditUserAvatarProvider } from 'lib/components/edit-user-avatar-provider.react.js';
import { FarcasterDataHandler } from 'lib/components/farcaster-data-handler.react.js';
+import { GlobalSearchIndexProvider } from 'lib/components/global-search-index-provider.react.js';
import {
ModalProvider,
useModalContext,
@@ -245,24 +246,26 @@
<TooltipProvider>
<MessageSearchStateProvider>
<ChatMentionContextProvider>
- <FocusHandler />
- <VisibilityHandler />
- <PolicyAcknowledgmentHandler />
- <PushNotificationsHandler />
- <InviteLinkHandler />
- <InviteLinksRefresher />
- <CommunitiesRefresher />
- <MinVersionHandler />
- <PlatformDetailsSynchronizer />
- <LogOutIfMissingCSATHandler />
- <UserInfosHandler />
- <TunnelbrokerDeviceTokenHandler />
- <FarcasterDataHandler />
- <AutoJoinCommunityHandler />
- <SyncCommunityStoreHandler />
- <DMActivityHandler />
- <HoldersHandler />
- {content}
+ <GlobalSearchIndexProvider>
+ <FocusHandler />
+ <VisibilityHandler />
+ <PolicyAcknowledgmentHandler />
+ <PushNotificationsHandler />
+ <InviteLinkHandler />
+ <InviteLinksRefresher />
+ <CommunitiesRefresher />
+ <MinVersionHandler />
+ <PlatformDetailsSynchronizer />
+ <LogOutIfMissingCSATHandler />
+ <UserInfosHandler />
+ <TunnelbrokerDeviceTokenHandler />
+ <FarcasterDataHandler />
+ <AutoJoinCommunityHandler />
+ <SyncCommunityStoreHandler />
+ <DMActivityHandler />
+ <HoldersHandler />
+ {content}
+ </GlobalSearchIndexProvider>
</ChatMentionContextProvider>
</MessageSearchStateProvider>
</TooltipProvider>
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
@@ -3,7 +3,7 @@
import invariant from 'invariant';
import * as React from 'react';
-import { useGlobalThreadSearchIndex } from 'lib/selectors/nav-selectors.js';
+import { useGlobalThreadSearchIndex } from 'lib/components/global-search-index-provider.react.js';
import {
useOnScreenEntryEditableThreadInfos,
reorderThreadSearchResults,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 21, 6:13 AM (1 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2543799
Default Alt Text
D13902.id.diff (8 KB)
Attached To
Mode
D13902: [lib][native][web] Introduce GlobalSearchIndexContext
Attached
Detach File
Event Timeline
Log In to Comment