import * as React from 'react'; import {RouteProp, useNavigation} from '@react-navigation/native'; import {ProfileStackParams} from '../../routes/main'; import {CenteredView, CommentTile} from '../../components'; import {CommentType} from '../../types'; import {ScrollView, StyleSheet, Text, View} from 'react-native'; import {SCREEN_WIDTH} from '../../utils/screenDimensions'; import {Button} from 'react-native-elements'; import {AddComment} from '../../components/'; import {useEffect} from 'react'; import AsyncStorage from '@react-native-community/async-storage'; import {getMomentComments} from '../..//services'; import {useDispatch} from 'react-redux'; import {logout} from '../../store/actions'; /** * Comments Screen for an image uploaded * Displays all comments for a particular moment uploaded by the user followed by a text area to add the comment. * Comment is posted when return is pressed on the keypad. */ type MomentCommentsScreenRouteProps = RouteProp< ProfileStackParams, 'MomentCommentsScreen' >; interface MomentCommentsScreenProps { route: MomentCommentsScreenRouteProps; } const MomentCommentsScreen: React.FC = ({route}) => { const navigation = useNavigation(); const {moment_id, screenType} = route.params; const [commentsList, setCommentsList] = React.useState([]); const [newCommentsAvailable, setNewCommentsAvailable] = React.useState(true); const dispatch = useDispatch(); useEffect(() => { const loadComments = async () => { const token = await AsyncStorage.getItem('token'); if (!token) { dispatch(logout()); return; } getMomentComments(moment_id, setCommentsList, token); setNewCommentsAvailable(false); }; if (newCommentsAvailable) { loadComments(); } }, [dispatch, moment_id, newCommentsAvailable]); return (