diff options
author | Ashm Walia <ashmwalia@outlook.com> | 2021-01-25 18:00:44 -0800 |
---|---|---|
committer | Ashm Walia <ashmwalia@outlook.com> | 2021-01-25 18:00:44 -0800 |
commit | 755f4f540d3e759ff9ad3bc35c64b6f7fc83998b (patch) | |
tree | 6619de58ffcd0a5c9e32a612ffc82f0d65d041d9 /src/components/comments/CommentTile.tsx | |
parent | 6cd49ed14f99fe953026e54969abc6232f3aec57 (diff) |
Add provision to show and hide replies
Diffstat (limited to 'src/components/comments/CommentTile.tsx')
-rw-r--r-- | src/components/comments/CommentTile.tsx | 122 |
1 files changed, 102 insertions, 20 deletions
diff --git a/src/components/comments/CommentTile.tsx b/src/components/comments/CommentTile.tsx index 47f25a53..4221fd54 100644 --- a/src/components/comments/CommentTile.tsx +++ b/src/components/comments/CommentTile.tsx @@ -1,10 +1,19 @@ -import React from 'react'; +import React, {useState} from 'react'; import {Text, View} from 'react-native-animatable'; import {ProfilePreview} from '../profile'; -import {CommentType, ScreenType} from '../../types'; +import {CommentType, ScreenType, TypeOfComment} from '../../types'; import {StyleSheet} from 'react-native'; -import {getTimePosted} from '../../utils'; +import { + getTimePosted, + normalize, + SCREEN_HEIGHT, + SCREEN_WIDTH, +} from '../../utils'; import ClockIcon from '../../assets/icons/clock-icon-01.svg'; +import {COMMENT_REPLIES} from '../../constants'; +import BackIcon from '../../assets/icons/back-arrow-colored.svg'; +import {TouchableOpacity} from 'react-native-gesture-handler'; +// 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. @@ -13,33 +22,78 @@ import ClockIcon from '../../assets/icons/clock-icon-01.svg'; interface CommentTileProps { comment_object: CommentType; screenType: ScreenType; + typeOfComment: TypeOfComment; } const CommentTile: React.FC<CommentTileProps> = ({ comment_object, screenType, + typeOfComment, }) => { const timePosted = getTimePosted(comment_object.date_created); + const [showReplies, setShowReplies] = useState<boolean>(false); + + const isThread = typeOfComment === 'Thread'; + return ( - <View style={styles.container}> - <ProfilePreview - profilePreview={{ - id: comment_object.commenter.id, - username: comment_object.commenter.username, - first_name: comment_object.commenter.first_name, - last_name: comment_object.commenter.last_name, - }} - previewType={'Comment'} - screenType={screenType} - /> - <View style={styles.body}> - <Text style={styles.comment}>{comment_object.comment}</Text> - <View style={styles.clockIconAndTime}> - <ClockIcon style={styles.clockIcon} /> - <Text style={styles.date_time}>{' ' + timePosted}</Text> + <> + <View style={styles.container}> + <ProfilePreview + profilePreview={{ + id: comment_object.commenter.id, + username: comment_object.commenter.username, + first_name: comment_object.commenter.first_name, + last_name: comment_object.commenter.last_name, + }} + previewType={'Comment'} + screenType={screenType} + /> + <View style={styles.body}> + <Text style={styles.comment}>{comment_object.comment}</Text> + <View style={styles.clockIconAndTime}> + <ClockIcon style={styles.clockIcon} /> + <Text style={styles.date_time}>{' ' + timePosted}</Text> + {typeOfComment === 'Comment' && ( + <> + <TouchableOpacity + onPress={() => { + setShowReplies(!showReplies); + }}> + <View style={styles.repliesTextAndIconContainer}> + <Text style={styles.repliesText}> + {showReplies ? 'Hide' : 'Replies'} + </Text> + <BackIcon + width={12} + height={11} + color={COMMENT_REPLIES} + style={ + !showReplies + ? styles.repliesDownArrow + : styles.repliesUpArrow + } + /> + </View> + </TouchableOpacity> + </> + )} + </View> </View> </View> - </View> + {/* {showReplies && ( + <View style={styles.repliesBody}> + <CommentsContainer + moment_id={'5a9d6023-bc62-4588-a3dc-8de2c9c370e0'} + screenType={screenType} + setNewCommentsAvailable={(value: boolean) => { + console.log(value); + }} + newCommentsAvailable={true} + typeOfComment={'Thread'} + /> + </View> + )} */} + </> ); }; @@ -61,6 +115,7 @@ const styles = StyleSheet.create({ }, date_time: { color: 'gray', + fontSize: normalize(12), }, clockIcon: { width: 12, @@ -71,6 +126,33 @@ const styles = StyleSheet.create({ flexDirection: 'row', marginBottom: '3%', }, + + repliesTextAndIconContainer: { + marginLeft: SCREEN_WIDTH * 0.37, + flexDirection: 'row', + }, + + repliesText: { + color: COMMENT_REPLIES, + fontWeight: '500', + fontSize: normalize(12), + marginRight: '3%', + }, + + repliesBody: { + width: SCREEN_WIDTH, + height: SCREEN_HEIGHT * 0.8, + }, + + repliesDownArrow: { + transform: [{rotate: '270deg'}], + marginTop: '7%', + }, + + repliesUpArrow: { + transform: [{rotate: '90deg'}], + marginTop: '7%', + }, }); export default CommentTile; |