From 85c0f668665696ba8127ee1ea436d10ec0af955f Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Wed, 27 Jan 2021 08:24:43 -0800 Subject: Pre-final --- src/components/comments/AddComment.tsx | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/components/comments/AddComment.tsx') diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index 7b04085d..86f4170c 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useRef} from 'react'; import { Image, Keyboard, @@ -11,7 +11,7 @@ import {TextInput, TouchableOpacity} from 'react-native-gesture-handler'; import {useSelector} from 'react-redux'; import UpArrowIcon from '../../assets/icons/up_arrow.svg'; import {TAGG_LIGHT_BLUE} from '../../constants'; -import {postMomentComment} from '../../services'; +import {postComment} from '../../services'; import {RootState} from '../../store/rootreducer'; import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; @@ -23,28 +23,27 @@ import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; export interface AddCommentProps { setNewCommentsAvailable: Function; - moment_id: string; + objectId: string; placeholderText: string; + isThreadInFocus: boolean; } const AddComment: React.FC = ({ setNewCommentsAvailable, - moment_id, + objectId, placeholderText, + isThreadInFocus, }) => { const [comment, setComment] = React.useState(''); const [keyboardVisible, setKeyboardVisible] = React.useState(false); - const { - avatar, - user: {userId}, - } = useSelector((state: RootState) => state.user); + const {avatar} = useSelector((state: RootState) => state.user); - const postComment = async () => { - const postedComment = await postMomentComment( - userId, + const addComment = async () => { + const postedComment = await postComment( comment.trim(), - moment_id, + objectId, + isThreadInFocus, ); if (postedComment) { @@ -65,6 +64,13 @@ const AddComment: React.FC = ({ return () => Keyboard.removeListener('keyboardWillHide', hideKeyboard); }, []); + const ref = useRef(null); + useEffect(() => { + if (isThreadInFocus) { + ref.current?.focus(); + } + }, [isThreadInFocus]); + return ( = ({ value={comment} autoCorrect={false} multiline={true} + ref={ref} /> - + @@ -102,6 +109,7 @@ const AddComment: React.FC = ({ ); }; + const styles = StyleSheet.create({ container: { backgroundColor: '#f7f7f7', -- cgit v1.2.3-70-g09d2