aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-14 17:50:36 -0400
committerIvan Chen <ivan@tagg.id>2021-05-14 17:50:36 -0400
commit33f5aa154457fb62099e56716ca5ae45feb98730 (patch)
tree0309419508ca511795d8984de302c93a9fe69a74
parenta8963146c72be5b048d061df2dbcc322cb674877 (diff)
linted
-rw-r--r--src/components/comments/MentionInputControlled.tsx97
-rw-r--r--src/components/moments/MomentPostHeader.tsx12
2 files changed, 56 insertions, 53 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>
);
diff --git a/src/components/moments/MomentPostHeader.tsx b/src/components/moments/MomentPostHeader.tsx
index f8c79ad9..3c3ee4c3 100644
--- a/src/components/moments/MomentPostHeader.tsx
+++ b/src/components/moments/MomentPostHeader.tsx
@@ -1,4 +1,5 @@
-import React, {useEffect, useState} from 'react';
+import {useNavigation} from '@react-navigation/native';
+import React, {useState} from 'react';
import {
StyleSheet,
Text,
@@ -6,14 +7,13 @@ import {
View,
ViewProps,
} from 'react-native';
-import {MomentMoreInfoDrawer} from '../profile';
-import {loadUserMoments} from '../../store/actions';
import {useDispatch, useSelector, useStore} from 'react-redux';
-import {ScreenType} from '../../types';
-import TaggAvatar from '../profile/TaggAvatar';
-import {useNavigation} from '@react-navigation/native';
+import {loadUserMoments} from '../../store/actions';
import {RootState} from '../../store/rootReducer';
+import {ScreenType} from '../../types';
import {fetchUserX, userXInStore} from '../../utils';
+import {MomentMoreInfoDrawer} from '../profile';
+import TaggAvatar from '../profile/TaggAvatar';
interface MomentPostHeaderProps extends ViewProps {
userXId?: string;