Changeset View
Changeset View
Standalone View
Standalone View
native/chat/chat-input-bar.react.js
Show All 35 Lines | import { | ||||
useThreadChatMentionCandidates, | useThreadChatMentionCandidates, | ||||
} from 'lib/hooks/chat-mention-hooks.js'; | } from 'lib/hooks/chat-mention-hooks.js'; | ||||
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; | import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; | ||||
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; | import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; | ||||
import { colorIsDark } from 'lib/shared/color-utils.js'; | import { colorIsDark } from 'lib/shared/color-utils.js'; | ||||
import { useEditMessage } from 'lib/shared/edit-messages-utils.js'; | import { useEditMessage } from 'lib/shared/edit-messages-utils.js'; | ||||
import { | import { | ||||
useMentionTypeaheadUserSuggestions, | useMentionTypeaheadUserSuggestions, | ||||
getMentionTypeaheadChatSuggestions, | useMentionTypeaheadChatSuggestions, | ||||
getTypeaheadRegexMatches, | getTypeaheadRegexMatches, | ||||
type Selection, | type Selection, | ||||
useUserMentionsCandidates, | useUserMentionsCandidates, | ||||
type MentionTypeaheadSuggestionItem, | type MentionTypeaheadSuggestionItem, | ||||
type TypeaheadMatchedStrings, | type TypeaheadMatchedStrings, | ||||
} from 'lib/shared/mention-utils.js'; | } from 'lib/shared/mention-utils.js'; | ||||
import { | import { | ||||
useNextLocalID, | useNextLocalID, | ||||
▲ Show 20 Lines • Show All 1,258 Lines • ▼ Show 20 Lines | const typeaheadMatchedStrings: ?TypeaheadMatchedStrings = | ||||
}, [typeaheadRegexMatches]); | }, [typeaheadRegexMatches]); | ||||
const suggestedUsers = useMentionTypeaheadUserSuggestions( | const suggestedUsers = useMentionTypeaheadUserSuggestions( | ||||
userMentionsCandidates, | userMentionsCandidates, | ||||
viewerID, | viewerID, | ||||
typeaheadMatchedStrings, | typeaheadMatchedStrings, | ||||
); | ); | ||||
const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> = | const suggestedChats = useMentionTypeaheadChatSuggestions( | ||||
React.useMemo(() => { | |||||
if (!typeaheadRegexMatches || !typeaheadMatchedStrings) { | |||||
return []; | |||||
} | |||||
const suggestedChats = getMentionTypeaheadChatSuggestions( | |||||
chatMentionSearchIndex, | chatMentionSearchIndex, | ||||
chatMentionCandidates, | chatMentionCandidates, | ||||
typeaheadMatchedStrings.query, | typeaheadMatchedStrings, | ||||
); | ); | ||||
return [...suggestedUsers, ...suggestedChats]; | const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> = | ||||
}, [ | React.useMemo( | ||||
chatMentionCandidates, | () => [...suggestedUsers, ...suggestedChats], | ||||
chatMentionSearchIndex, | [suggestedUsers, suggestedChats], | ||||
typeaheadRegexMatches, | ); | ||||
typeaheadMatchedStrings, | |||||
suggestedUsers, | |||||
]); | |||||
return ( | return ( | ||||
<ChatInputBar | <ChatInputBar | ||||
{...props} | {...props} | ||||
viewerID={viewerID} | viewerID={viewerID} | ||||
draft={draft} | draft={draft} | ||||
joinThreadLoadingStatus={joinThreadLoadingStatus} | joinThreadLoadingStatus={joinThreadLoadingStatus} | ||||
threadCreationInProgress={threadCreationInProgress} | threadCreationInProgress={threadCreationInProgress} | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |