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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
import React, {useEffect, useState} from 'react';
import {StyleSheet, View, Image, Text} from 'react-native';
import {Button} from 'react-native-elements';
import {BlurView} from '@react-native-community/blur';
import {
SCREEN_HEIGHT,
SCREEN_WIDTH,
StatusBarHeight,
getTimePosted,
} from '../../utils';
import {UserType, CommentType} from '../../types';
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import {CaptionScreenHeader} from '../../components';
import {AuthContext} from '../../routes/authentication';
import {ProfileStackParams} from 'src/routes/profile/ProfileStack';
import Animated from 'react-native-reanimated';
import {CommentsCount} from '../../components';
import AsyncStorage from '@react-native-community/async-storage';
import {getMomentCommentsCount} from '../../services';
const NO_USER: UserType = {
userId: '',
username: '',
};
/**
* Individual moment view opened when user clicks on a moment tile
*/
type IndividualMomentRouteProp = RouteProp<
ProfileStackParams,
'IndividualMoment'
>;
type IndividualMomentNavigationProp = StackNavigationProp<
ProfileStackParams,
'IndividualMoment'
>;
interface IndividualMomentProps {
route: IndividualMomentRouteProp;
navigation: IndividualMomentNavigationProp;
}
const IndividualMoment: React.FC<IndividualMomentProps> = ({
route,
navigation,
}) => {
const {
moment_category,
path_hash,
date_time,
moment_id,
} = route.params.moment;
const {isProfileView} = route.params;
const {
user: {userId},
logout,
} = React.useContext(AuthContext);
const [user, setUser] = useState<UserType>(NO_USER);
const [caption, setCaption] = React.useState(route.params.moment.caption);
const [elapsedTime, setElapsedTime] = React.useState<string>();
const [comments_count, setCommentsCount] = React.useState('');
const handleCaptionUpdate = (caption: string) => {
setCaption(caption);
};
useEffect(() => {
if (!userId) {
setUser(NO_USER);
}
const timePeriod = async () => {
setElapsedTime(getTimePosted(date_time));
};
const loadComments = async () => {
const token = await AsyncStorage.getItem('token');
if (!token) {
logout();
return;
}
getMomentCommentsCount(moment_id, setCommentsCount, token);
};
timePeriod();
loadComments();
}, [date_time, userId]);
return (
<BlurView
blurType="light"
blurAmount={10}
reducedTransparencyFallbackColor="white"
style={styles.contentContainer}>
<View style={styles.buttonsContainer}>
<Button
title="Close"
buttonStyle={styles.button}
onPress={() => {
navigation.pop();
}}
/>
</View>
<CaptionScreenHeader
style={styles.header}
{...{title: moment_category}}
/>
<Image
style={styles.image}
source={{uri: path_hash}}
resizeMode={'cover'}
/>
<View style={styles.bodyContainer}>
<CommentsCount
comments_count={comments_count}
isProfileView={isProfileView}
moment_id={moment_id}
/>
<Animated.Text style={styles.text}>{elapsedTime}</Animated.Text>
</View>
<Animated.Text style={styles.text}>{caption}</Animated.Text>
</BlurView>
);
};
const styles = StyleSheet.create({
contentContainer: {
width: SCREEN_WIDTH,
paddingTop: StatusBarHeight,
paddingBottom: SCREEN_HEIGHT,
},
buttonsContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginLeft: '3%',
marginRight: '3%',
},
button: {
backgroundColor: 'transparent',
},
shareButtonTitle: {
fontWeight: 'bold',
color: '#6EE7E7',
},
header: {
marginVertical: 20,
},
image: {
position: 'relative',
width: SCREEN_WIDTH,
aspectRatio: 1,
marginBottom: '3%',
},
bodyContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginLeft: '7%',
marginRight: '5%',
marginBottom: '2%',
},
text: {
position: 'relative',
paddingBottom: '1%',
paddingTop: '1%',
marginLeft: '7%',
marginRight: '2%',
color: '#ffffff',
fontWeight: 'bold',
},
});
export default IndividualMoment;
|