From 4bc27c266710fbab8c028c6fdbaf4fd158b3dcc2 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Mon, 10 May 2021 15:10:31 -0700 Subject: Fixed up keyboard mentions --- src/components/comments/AddComment.tsx | 2 +- src/components/common/TaggTypeahead.tsx | 8 ++++++-- src/utils/comments.tsx | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index 9cf10b5e..7e440daf 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -123,7 +123,7 @@ const AddComment: React.FC = ({momentId, placeholderText}) => { ); }} inputRef={ref} - partTypes={mentionPartTypes('blue')} + partTypes={mentionPartTypes('blue', ref)} /> diff --git a/src/components/common/TaggTypeahead.tsx b/src/components/common/TaggTypeahead.tsx index 7cd99278..bef72851 100644 --- a/src/components/common/TaggTypeahead.tsx +++ b/src/components/common/TaggTypeahead.tsx @@ -8,6 +8,7 @@ import {SCREEN_WIDTH} from '../../utils'; import TaggUserRowCell from './TaggUserRowCell'; const TaggTypeahead: React.FC = ({ + textRef, keyword, onSuggestionPress, }) => { @@ -19,7 +20,7 @@ const TaggTypeahead: React.FC = ({ }, [keyword]); const getQuerySuggested = async () => { - if (!keyword || keyword.length < 3) { + if (!keyword) { setResults([]); return; } @@ -41,7 +42,9 @@ const TaggTypeahead: React.FC = ({ showsVerticalScrollIndicator={false} onLayout={(event) => { setHeight(event.nativeEvent.layout.height); - }}> + }} + keyboardShouldPersistTaps={'always'} + > {results.map((user) => ( { @@ -50,6 +53,7 @@ const TaggTypeahead: React.FC = ({ name: user.username, }); setResults([]); + textRef.current.focus(); }} user={user} /> diff --git a/src/utils/comments.tsx b/src/utils/comments.tsx index 0d551682..d7091d1e 100644 --- a/src/utils/comments.tsx +++ b/src/utils/comments.tsx @@ -78,13 +78,14 @@ export const renderTextWithMentions: React.FC = ({ ); }; -export const mentionPartTypes: (style: 'blue' | 'white') => PartType[] = ( +export const mentionPartTypes: (style: 'blue' | 'white', textRef: any) => PartType[] = ( style, + textRef ) => { return [ { trigger: '@', - renderSuggestions: (props) => , + renderSuggestions: (props) => , allowedSpacesCount: 0, isInsertSpaceAfterMention: true, textStyle: -- cgit v1.2.3-70-g09d2 From 517616f21aa3644103b185884e2c233056e316d8 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Mon, 10 May 2021 15:22:00 -0700 Subject: Removed unneeded ref variables --- src/components/comments/AddComment.tsx | 2 +- src/components/common/TaggTypeahead.tsx | 2 -- src/utils/comments.tsx | 5 ++--- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index 7e440daf..9cf10b5e 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -123,7 +123,7 @@ const AddComment: React.FC = ({momentId, placeholderText}) => { ); }} inputRef={ref} - partTypes={mentionPartTypes('blue', ref)} + partTypes={mentionPartTypes('blue')} /> diff --git a/src/components/common/TaggTypeahead.tsx b/src/components/common/TaggTypeahead.tsx index bef72851..fcf196bd 100644 --- a/src/components/common/TaggTypeahead.tsx +++ b/src/components/common/TaggTypeahead.tsx @@ -8,7 +8,6 @@ import {SCREEN_WIDTH} from '../../utils'; import TaggUserRowCell from './TaggUserRowCell'; const TaggTypeahead: React.FC = ({ - textRef, keyword, onSuggestionPress, }) => { @@ -53,7 +52,6 @@ const TaggTypeahead: React.FC = ({ name: user.username, }); setResults([]); - textRef.current.focus(); }} user={user} /> diff --git a/src/utils/comments.tsx b/src/utils/comments.tsx index d7091d1e..0d551682 100644 --- a/src/utils/comments.tsx +++ b/src/utils/comments.tsx @@ -78,14 +78,13 @@ export const renderTextWithMentions: React.FC = ({ ); }; -export const mentionPartTypes: (style: 'blue' | 'white', textRef: any) => PartType[] = ( +export const mentionPartTypes: (style: 'blue' | 'white') => PartType[] = ( style, - textRef ) => { return [ { trigger: '@', - renderSuggestions: (props) => , + renderSuggestions: (props) => , allowedSpacesCount: 0, isInsertSpaceAfterMention: true, textStyle: -- cgit v1.2.3-70-g09d2 From 25be50b286034edad75a47ce676401e67746469f Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 10 May 2021 19:38:03 -0400 Subject: added default friends suggestions --- src/components/common/TaggTypeahead.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/components/common/TaggTypeahead.tsx b/src/components/common/TaggTypeahead.tsx index fcf196bd..747e0bb5 100644 --- a/src/components/common/TaggTypeahead.tsx +++ b/src/components/common/TaggTypeahead.tsx @@ -1,26 +1,32 @@ import React, {Fragment, useEffect, useState} from 'react'; import {ScrollView, StyleSheet} from 'react-native'; import {MentionSuggestionsProps} from 'react-native-controlled-mentions'; +import {useSelector} from 'react-redux'; import {SEARCH_ENDPOINT_MESSAGES} from '../../constants'; import {loadSearchResults} from '../../services'; +import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType} from '../../types'; -import {SCREEN_WIDTH} from '../../utils'; +import {SCREEN_WIDTH, shuffle} from '../../utils'; import TaggUserRowCell from './TaggUserRowCell'; const TaggTypeahead: React.FC = ({ keyword, onSuggestionPress, }) => { + const {friends} = useSelector((state: RootState) => state.friends); const [results, setResults] = useState([]); const [height, setHeight] = useState(0); useEffect(() => { - getQuerySuggested(); + if (keyword === '') { + setResults(shuffle(friends)); + } else { + getQuerySuggested(); + } }, [keyword]); const getQuerySuggested = async () => { - if (!keyword) { - setResults([]); + if (keyword === undefined || keyword === '@') { return; } const searchResults = await loadSearchResults( @@ -42,16 +48,15 @@ const TaggTypeahead: React.FC = ({ onLayout={(event) => { setHeight(event.nativeEvent.layout.height); }} - keyboardShouldPersistTaps={'always'} - > + keyboardShouldPersistTaps={'always'}> {results.map((user) => ( { + setResults([]); onSuggestionPress({ id: user.id, name: user.username, }); - setResults([]); }} user={user} /> -- cgit v1.2.3-70-g09d2