Changeset View
Changeset View
Standalone View
Standalone View
web/chat/chat-input-bar.react.js
Show All 13 Lines | import { | ||||
useChatMentionContext, | useChatMentionContext, | ||||
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 { | import { | ||||
getTypeaheadRegexMatches, | getTypeaheadRegexMatches, | ||||
useUserMentionsCandidates, | useUserMentionsCandidates, | ||||
getMentionTypeaheadChatSuggestions, | useMentionTypeaheadChatSuggestions, | ||||
type MentionTypeaheadSuggestionItem, | type MentionTypeaheadSuggestionItem, | ||||
type TypeaheadMatchedStrings, | type TypeaheadMatchedStrings, | ||||
useMentionTypeaheadUserSuggestions, | useMentionTypeaheadUserSuggestions, | ||||
} from 'lib/shared/mention-utils.js'; | } from 'lib/shared/mention-utils.js'; | ||||
import { localIDPrefix, trimMessage } from 'lib/shared/message-utils.js'; | import { localIDPrefix, trimMessage } from 'lib/shared/message-utils.js'; | ||||
import { | import { | ||||
threadHasPermission, | threadHasPermission, | ||||
viewerIsMember, | viewerIsMember, | ||||
▲ Show 20 Lines • Show All 611 Lines • ▼ Show 20 Lines | React.memo<BaseProps>(function ConnectedChatInputBar(props) { | ||||
]); | ]); | ||||
const suggestedUsers = useMentionTypeaheadUserSuggestions( | const suggestedUsers = useMentionTypeaheadUserSuggestions( | ||||
props.inputState.typeaheadState.frozenUserMentionsCandidates, | props.inputState.typeaheadState.frozenUserMentionsCandidates, | ||||
viewerID, | viewerID, | ||||
typeaheadMatchedStrings, | typeaheadMatchedStrings, | ||||
); | ); | ||||
const suggestions = React.useMemo(() => { | const suggestedChats = useMentionTypeaheadChatSuggestions( | ||||
if (!typeaheadMatchedStrings) { | |||||
return ([]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>); | |||||
} | |||||
const suggestedChats = getMentionTypeaheadChatSuggestions( | |||||
chatMentionSearchIndex, | chatMentionSearchIndex, | ||||
props.inputState.typeaheadState.frozenChatMentionsCandidates, | props.inputState.typeaheadState.frozenChatMentionsCandidates, | ||||
typeaheadMatchedStrings.query, | |||||
); | |||||
return ([ | |||||
...suggestedUsers, | |||||
...suggestedChats, | |||||
]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>); | |||||
}, [ | |||||
suggestedUsers, | |||||
typeaheadMatchedStrings, | typeaheadMatchedStrings, | ||||
props.inputState.typeaheadState.frozenChatMentionsCandidates, | ); | ||||
chatMentionSearchIndex, | |||||
]); | const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> = | ||||
React.useMemo( | |||||
() => [...suggestedUsers, ...suggestedChats], | |||||
[suggestedUsers, suggestedChats], | |||||
); | |||||
return ( | return ( | ||||
<ChatInputBar | <ChatInputBar | ||||
{...props} | {...props} | ||||
viewerID={viewerID} | viewerID={viewerID} | ||||
joinThreadLoadingStatus={joinThreadLoadingStatus} | joinThreadLoadingStatus={joinThreadLoadingStatus} | ||||
threadCreationInProgress={threadCreationInProgress} | threadCreationInProgress={threadCreationInProgress} | ||||
calendarQuery={calendarQuery} | calendarQuery={calendarQuery} | ||||
Show All 13 Lines |