import React, {useState} from 'react'; import {Text, View} from 'react-native-animatable'; import {ProfilePreview} from '../profile'; import {CommentType, ScreenType, TypeOfComment} from '../../types'; import {StyleSheet} from 'react-native'; import ClockIcon from '../../assets/icons/clock-icon-01.svg'; import {COMMENT_REPLIES} from '../../constants'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {getTimePosted, normalize, SCREEN_WIDTH} from '../../utils'; import Arrow from '../../assets/icons/back-arrow-colored.svg'; import CommentsContainer from './CommentsContainer'; /** * Displays users's profile picture, comment posted by them and the time difference between now and when a comment was posted. */ interface CommentTileProps { comment_object: CommentType; screenType: ScreenType; typeOfComment: TypeOfComment; setCommentObjectInFocus?: (comment: CommentType | undefined) => void; } const CommentTile: React.FC = ({ comment_object, screenType, typeOfComment, setCommentObjectInFocus, }) => { const timePosted = getTimePosted(comment_object.date_created); const [showReplies, setShowReplies] = useState(false); const toggleReplies = () => { if (setCommentObjectInFocus) { if (!showReplies) { setCommentObjectInFocus(comment_object); } else { setCommentObjectInFocus(undefined); } } setShowReplies(!showReplies); }; const getRepliesText = () => showReplies ? 'Hide' : comment_object.replies_count > 0 ? `Replies (${comment_object.replies_count})` : 'Replies'; return ( <> {comment_object.comment} {' ' + timePosted} {typeOfComment === 'Comment' && comment_object.replies_count > 0 && ( {getRepliesText()} )} {showReplies && ( {}} newCommentsAvailable={true} typeOfComment={'Thread'} /> )} ); }; const styles = StyleSheet.create({ container: { marginHorizontal: '3%', borderBottomWidth: 1, borderColor: 'lightgray', marginBottom: '3%', flexDirection: 'column', flex: 1, }, moreMarginWithThread: { marginHorizontal: '7%', }, body: { marginLeft: 56, }, comment: { marginBottom: '2%', top: -5, }, date_time: { color: 'gray', fontSize: normalize(12), }, clockIcon: { width: 12, height: 12, alignSelf: 'center', }, clockIconAndTime: { flexDirection: 'row', marginBottom: '3%', }, flexer: { flex: 1, }, repliesTextAndIconContainer: { flexDirection: 'row', alignItems: 'center', }, repliesText: { color: COMMENT_REPLIES, fontWeight: '500', fontSize: normalize(12), marginRight: '3%', }, repliesBody: { width: SCREEN_WIDTH, }, repliesDownArrow: { transform: [{rotate: '270deg'}], marginTop: '7%', }, repliesUpArrow: { transform: [{rotate: '90deg'}], marginTop: '7%', }, }); export default CommentTile;