Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32212939
D10432.1765145390.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D10432.1765145390.diff
View Options
diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js
--- a/lib/shared/mention-utils.js
+++ b/lib/shared/mention-utils.js
@@ -134,23 +134,32 @@
}, [userSearchIndex, resolvedThredMembers, usernamePrefix, viewerID]);
}
-function getMentionTypeaheadChatSuggestions(
+function useMentionTypeaheadChatSuggestions(
chatSearchIndex: SentencePrefixSearchIndex,
chatMentionCandidates: ChatMentionCandidates,
- chatNamePrefix: string,
+ typeaheadMatchedStrings: ?TypeaheadMatchedStrings,
): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> {
- const result = [];
- const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix);
- for (const threadID of threadIDs) {
- if (!chatMentionCandidates[threadID]) {
- continue;
+ const chatNamePrefix: ?string = typeaheadMatchedStrings?.query;
+
+ return React.useMemo(() => {
+ const result = [];
+
+ if (chatNamePrefix === undefined || chatNamePrefix === null) {
+ return result;
}
- result.push({
- type: 'chat',
- threadInfo: chatMentionCandidates[threadID],
- });
- }
- return result;
+
+ const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix);
+ for (const threadID of threadIDs) {
+ if (!chatMentionCandidates[threadID]) {
+ continue;
+ }
+ result.push({
+ type: 'chat',
+ threadInfo: chatMentionCandidates[threadID],
+ });
+ }
+ return result;
+ }, [chatSearchIndex, chatMentionCandidates, chatNamePrefix]);
}
function getNewTextAndSelection(
@@ -197,7 +206,7 @@
isUserMentioned,
extractUserMentionsFromText,
useMentionTypeaheadUserSuggestions,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
getNewTextAndSelection,
getTypeaheadRegexMatches,
useUserMentionsCandidates,
diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js
--- a/native/chat/chat-input-bar.react.js
+++ b/native/chat/chat-input-bar.react.js
@@ -41,7 +41,7 @@
import { useEditMessage } from 'lib/shared/edit-messages-utils.js';
import {
useMentionTypeaheadUserSuggestions,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
getTypeaheadRegexMatches,
type Selection,
useUserMentionsCandidates,
@@ -1316,26 +1316,17 @@
typeaheadMatchedStrings,
);
- const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
- React.useMemo(() => {
- if (!typeaheadRegexMatches || !typeaheadMatchedStrings) {
- return [];
- }
-
- const suggestedChats = getMentionTypeaheadChatSuggestions(
- chatMentionSearchIndex,
- chatMentionCandidates,
- typeaheadMatchedStrings.query,
- );
+ const suggestedChats = useMentionTypeaheadChatSuggestions(
+ chatMentionSearchIndex,
+ chatMentionCandidates,
+ typeaheadMatchedStrings,
+ );
- return [...suggestedUsers, ...suggestedChats];
- }, [
- chatMentionCandidates,
- chatMentionSearchIndex,
- typeaheadRegexMatches,
- typeaheadMatchedStrings,
- suggestedUsers,
- ]);
+ const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
+ React.useMemo(
+ () => [...suggestedUsers, ...suggestedChats],
+ [suggestedUsers, suggestedChats],
+ );
return (
<ChatInputBar
diff --git a/web/chat/chat-input-bar.react.js b/web/chat/chat-input-bar.react.js
--- a/web/chat/chat-input-bar.react.js
+++ b/web/chat/chat-input-bar.react.js
@@ -19,7 +19,7 @@
import {
getTypeaheadRegexMatches,
useUserMentionsCandidates,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
type MentionTypeaheadSuggestionItem,
type TypeaheadMatchedStrings,
useMentionTypeaheadUserSuggestions,
@@ -647,25 +647,17 @@
typeaheadMatchedStrings,
);
- const suggestions = React.useMemo(() => {
- if (!typeaheadMatchedStrings) {
- return ([]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>);
- }
- const suggestedChats = getMentionTypeaheadChatSuggestions(
- chatMentionSearchIndex,
- props.inputState.typeaheadState.frozenChatMentionsCandidates,
- typeaheadMatchedStrings.query,
- );
- return ([
- ...suggestedUsers,
- ...suggestedChats,
- ]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>);
- }, [
- suggestedUsers,
- typeaheadMatchedStrings,
- props.inputState.typeaheadState.frozenChatMentionsCandidates,
+ const suggestedChats = useMentionTypeaheadChatSuggestions(
chatMentionSearchIndex,
- ]);
+ props.inputState.typeaheadState.frozenChatMentionsCandidates,
+ typeaheadMatchedStrings,
+ );
+
+ const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
+ React.useMemo(
+ () => [...suggestedUsers, ...suggestedChats],
+ [suggestedUsers, suggestedChats],
+ );
return (
<ChatInputBar
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 10:09 PM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5846140
Default Alt Text
D10432.1765145390.diff (4 KB)
Attached To
Mode
D10432: [lib/web/native] Convert getMentionTypeaheadUserSuggestions into a hook
Attached
Detach File
Event Timeline
Log In to Comment