diff options
author | Ivan Chen <ivan@tagg.id> | 2021-05-04 15:02:12 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-05-04 20:48:07 -0400 |
commit | c5cfb608eeb512c3b00c20776b63faf70943b76e (patch) | |
tree | ddd5a0c01c7bc65499f463c0b5090e0dc18ff9f8 /src/components | |
parent | e67c5d50ebd33967c069134aa0e03111674e1c5d (diff) |
fixed issue where mention doesn't go away
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/comments/AddComment.tsx | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index caba68d5..f9c5669b 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -43,6 +43,7 @@ const AddComment: React.FC<AddCommentProps> = ({ placeholderText, isReplying, }) => { + const [inReplyToMention, setInReplyToMention] = useState(''); const [comment, setComment] = useState(''); const [keyboardVisible, setKeyboardVisible] = useState(false); const {avatar} = useSelector((state: RootState) => state.user); @@ -78,13 +79,6 @@ const AddComment: React.FC<AddCommentProps> = ({ }; useEffect(() => { - if (isReplying && commentInReplyTo) { - const commenter = commentInReplyTo.commenter; - setComment(`@[${commenter.username}](${commenter.id}) `); - } - }, [isReplying, commentInReplyTo]); - - useEffect(() => { const showKeyboard = () => setKeyboardVisible(true); Keyboard.addListener('keyboardWillShow', showKeyboard); return () => Keyboard.removeListener('keyboardWillShow', showKeyboard); @@ -96,12 +90,16 @@ const AddComment: React.FC<AddCommentProps> = ({ return () => Keyboard.removeListener('keyboardWillHide', hideKeyboard); }, []); - //If a comment is in Focus, bring the keyboard up so user is able to type in a reply useEffect(() => { - if (isReplying) { + if (isReplying && commentInReplyTo) { + // bring up keyboard ref.current?.focus(); + const commenter = commentInReplyTo.commenter; + setInReplyToMention(`@[${commenter.username}](${commenter.id}) `); + } else { + setInReplyToMention(''); } - }, [isReplying]); + }, [isReplying, commentInReplyTo]); return ( <KeyboardAvoidingView @@ -117,7 +115,7 @@ const AddComment: React.FC<AddCommentProps> = ({ <MentionInput containerStyle={styles.text} placeholder={placeholderText} - value={comment} + value={inReplyToMention + comment} onChange={setComment} inputRef={ref} partTypes={mentionPartTypes} |