diff options
author | Ivan Chen <ivan@tagg.id> | 2021-05-14 17:50:36 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-05-14 17:50:36 -0400 |
commit | 33f5aa154457fb62099e56716ca5ae45feb98730 (patch) | |
tree | 0309419508ca511795d8984de302c93a9fe69a74 /src/components/comments | |
parent | a8963146c72be5b048d061df2dbcc322cb674877 (diff) |
linted
Diffstat (limited to 'src/components/comments')
-rw-r--r-- | src/components/comments/MentionInputControlled.tsx | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/components/comments/MentionInputControlled.tsx b/src/components/comments/MentionInputControlled.tsx index 6abcb566..2fd2b41d 100644 --- a/src/components/comments/MentionInputControlled.tsx +++ b/src/components/comments/MentionInputControlled.tsx @@ -6,7 +6,6 @@ import { TextInputSelectionChangeEventData, View, } from 'react-native'; - import { MentionInputProps, MentionPartType, @@ -43,16 +42,16 @@ const MentionInputControlled: FC<MentionInputProps> = ({ const validRegex = () => { if (partTypes.length === 0) { - return /.*\@[^ ]*$/; + return /.*@[^ ]*$/; } else { - return new RegExp(`.*\@${keywordByTrigger[partTypes[0].trigger]}.*$`); + return new RegExp(`.*@${keywordByTrigger[partTypes[0].trigger]}.*$`); } }; - const {plainText, parts} = useMemo(() => parseValue(value, partTypes), [ - value, - partTypes, - ]); + const {plainText, parts} = useMemo( + () => parseValue(value, partTypes), + [value, partTypes], + ); const handleSelectionChange = ( event: NativeSyntheticEvent<TextInputSelectionChangeEventData>, @@ -91,36 +90,35 @@ const MentionInputControlled: FC<MentionInputProps> = ({ * - Get updated value * - Trigger onChange callback with new value */ - const onSuggestionPress = (mentionType: MentionPartType) => ( - suggestion: Suggestion, - ) => { - const newValue = generateValueWithAddedSuggestion( - parts, - mentionType, - plainText, - selection, - suggestion, - ); - - if (!newValue) { - return; - } + const onSuggestionPress = + (mentionType: MentionPartType) => (suggestion: Suggestion) => { + const newValue = generateValueWithAddedSuggestion( + parts, + mentionType, + plainText, + selection, + suggestion, + ); + + if (!newValue) { + return; + } - onChange(newValue); + onChange(newValue); - /** - * Move cursor to the end of just added mention starting from trigger string and including: - * - Length of trigger string - * - Length of mention name - * - Length of space after mention (1) - * - * Not working now due to the RN bug - */ - // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + - // suggestion.name.length + 1; + /** + * Move cursor to the end of just added mention starting from trigger string and including: + * - Length of trigger string + * - Length of mention name + * - Length of space after mention (1) + * + * Not working now due to the RN bug + */ + // const newCursorPosition = currentPart.position.start + triggerPartIndex + trigger.length + + // suggestion.name.length + 1; - // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); - }; + // textInput.current?.setNativeProps({selection: {start: newCursorPosition, end: newCursorPosition}}); + }; const handleTextInputRef = (ref: TextInput) => { textInput.current = ref as TextInput; @@ -129,7 +127,8 @@ const MentionInputControlled: FC<MentionInputProps> = ({ if (typeof propInputRef === 'function') { propInputRef(ref); } else { - (propInputRef as MutableRefObject<TextInput>).current = ref as TextInput; + (propInputRef as MutableRefObject<TextInput>).current = + ref as TextInput; } } }; @@ -151,12 +150,14 @@ const MentionInputControlled: FC<MentionInputProps> = ({ return ( <View style={containerStyle}> {validateInput(keyboardText) - ? (partTypes.filter( - (one) => - isMentionPartType(one) && - one.renderSuggestions != null && - !one.isBottomMentionSuggestionsRender, - ) as MentionPartType[]).map(renderMentionSuggestions) + ? ( + partTypes.filter( + (one) => + isMentionPartType(one) && + one.renderSuggestions != null && + !one.isBottomMentionSuggestionsRender, + ) as MentionPartType[] + ).map(renderMentionSuggestions) : null} <TextInput @@ -181,12 +182,14 @@ const MentionInputControlled: FC<MentionInputProps> = ({ </TextInput> {validateInput(keyboardText) - ? (partTypes.filter( - (one) => - isMentionPartType(one) && - one.renderSuggestions != null && - one.isBottomMentionSuggestionsRender, - ) as MentionPartType[]).map(renderMentionSuggestions) + ? ( + partTypes.filter( + (one) => + isMentionPartType(one) && + one.renderSuggestions != null && + one.isBottomMentionSuggestionsRender, + ) as MentionPartType[] + ).map(renderMentionSuggestions) : null} </View> ); |