1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {Image, StyleSheet, Text, View} from 'react-native';
import {TouchableOpacity} from 'react-native-gesture-handler';
import {useDispatch, useStore} from 'react-redux';
import {MomentCommentPreviewType, ScreenType, UserType} from '../../types';
import {navigateToProfile, normalize} from '../../utils';
import {mentionPartTypes, renderTextWithMentions} from '../../utils/comments';
interface MomentCommentPreviewProps {
momentId: string;
commentsCount: number;
commentPreview: MomentCommentPreviewType | null;
screenType: ScreenType;
}
const MomentCommentPreview: React.FC<MomentCommentPreviewProps> = ({
momentId,
commentsCount,
commentPreview,
screenType,
}) => {
const navigation = useNavigation();
const state = useStore().getState();
const commentCountText =
!commentsCount || commentsCount === 0
? 'No Comments'
: commentsCount + ' comments';
return (
<TouchableOpacity
style={styles.commentsPreviewContainer}
onPress={() =>
navigation.push('MomentCommentsScreen', {
moment_id: momentId,
screenType,
})
}>
<Text style={styles.whiteBold}>{commentCountText}</Text>
{commentPreview && (
<View style={styles.previewContainer}>
<Image
source={{
uri: commentPreview.commenter.thumbnail_url,
}}
style={styles.avatar}
/>
<Text style={styles.whiteBold} numberOfLines={1}>
<Text> </Text>
<Text>{commentPreview.commenter.username}</Text>
<Text> </Text>
{renderTextWithMentions({
value: commentPreview.comment,
styles: styles.normalFont,
partTypes: mentionPartTypes('white', 'comment'),
onPress: (user: UserType) =>
navigateToProfile(
state,
useDispatch,
navigation,
screenType,
user,
),
})}
</Text>
</View>
)}
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
commentsPreviewContainer: {
height: normalize(50),
flexDirection: 'column',
justifyContent: 'space-around',
marginHorizontal: '5%',
marginBottom: '2%',
},
whiteBold: {
fontWeight: '700',
color: 'white',
fontSize: normalize(13),
},
previewContainer: {
flexDirection: 'row',
width: '95%',
},
avatar: {
height: normalize(16),
width: normalize(16),
borderRadius: 99,
},
normalFont: {
fontWeight: 'normal',
},
});
export default MomentCommentPreview;
|