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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import React, {Fragment, useRef, useState} from 'react';
import {
Alert,
Image,
Keyboard,
KeyboardAvoidingView,
Platform,
StyleSheet,
// Text,
TouchableWithoutFeedback,
View,
} from 'react-native';
import {MentionInput} from 'react-native-controlled-mentions';
import {Button} from 'react-native-elements';
import {useDispatch, useSelector} from 'react-redux';
import {SearchBackground} from '../../components';
import {CaptionScreenHeader} from '../../components/';
// import Draggable from '../../components/common/Draggable';
import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator';
// import TaggDraggable from '../../components/taggs/TaggDraggable';
import {TAGG_LIGHT_BLUE_2} from '../../constants';
import {ERROR_UPLOAD, SUCCESS_PIC_UPLOAD} from '../../constants/strings';
import {MainStackParams} from '../../routes';
import {postMoment} from '../../services';
import {
loadUserMoments,
updateProfileCompletionStage,
} from '../../store/actions';
import {RootState} from '../../store/rootReducer';
import {SCREEN_WIDTH, StatusBarHeight} from '../../utils';
import {mentionPartTypes} from '../../utils/comments';
// import {TouchableOpacity} from 'react-native-gesture-handler';
/**
* Upload Screen to allow users to upload posts to Tagg
*/
type CaptionScreenRouteProp = RouteProp<MainStackParams, 'CaptionScreen'>;
type CaptionScreenNavigationProp = StackNavigationProp<
MainStackParams,
'CaptionScreen'
>;
interface CaptionScreenProps {
route: CaptionScreenRouteProp;
navigation: CaptionScreenNavigationProp;
}
interface momentTag {
userID: string;
username: string;
xLocation: number;
yLocation: number;
}
const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const {title, image, screenType} = route.params;
const {
user: {userId},
} = useSelector((state: RootState) => state.user);
const dispatch = useDispatch();
const [caption, setCaption] = useState('');
const [loading, setLoading] = useState(false);
// const [isTop, setIsTop] = useState(false);
const imageRef = useRef(null);
// const zIndex = [0, 999];
// const [offset, setOffset] = useState([0, 0]);
// const [curStart, setCurStart] = useState([0, 0]);
// const [imageDimensions, setImageDimensions] = useState([0, 0]);
// created a state variable to keep track of every tag
// idea is that each element in the list
// const [taggList, setTaggList] = useState([
// {
// first_name: 'Ivan',
// id: 'cee45bf8-7f3d-43c8-99bb-ec04908efe58',
// last_name: 'Chen',
// thumbnail_url:
// 'https://tagg-dev.s3.us-east-2.amazonaws.com/thumbnails/smallProfilePicture/spp-cee45bf8-7f3d-43c8-99bb-ec04908efe58-thumbnail.jpg',
// username: 'ivan.tagg',
// },
// {
// first_name: 'Ankit',
// id: '3bcf6947-bee6-46b0-ad02-6f4d25eaeac3',
// last_name: 'Thanekar',
// thumbnail_url:
// 'https://tagg-dev.s3.us-east-2.amazonaws.com/thumbnails/smallProfilePicture/spp-3bcf6947-bee6-46b0-ad02-6f4d25eaeac3-thumbnail.jpg',
// username: 'ankit.thanekar',
// },
// ]);
// state variables used to position draggables
// state var used to keep track of draggable z ordering
// const [layerOrder, setLayerOrder] = useState<string[]>([]);
// created a test user - BUG - failed to register a profile visit -
// const testUser: UserType = {
// userId: 'ID-1234-567',
// username: 'dragonofthewest',
// };
const navigateToProfile = () => {
//Since the logged In User is navigating to own profile, useXId is not required
navigation.navigate('Profile', {
screenType,
userXId: undefined,
});
};
/**
* Helper function that we use to keep track of which element should be on top most layer
* @param index
*/
// const bringToFront = (index: number) => {
// let currUser = taggList[index].id;
// if (layerOrder.includes(currUser)) {
// layerOrder.splice(layerOrder.indexOf(currUser), 1);
// }
// layerOrder.push(currUser);
// setLayerOrder(layerOrder);
// };
/**
* Helper function that tells us if the current draggable is the topmost one.
* @param index
*/
// const isOnTop = (index: number) => {
// let currUser = taggList[index].id;
// return currUser === layerOrder[0];
// };
/**
* function that sets the initial position of each newly created tag
* @returns
*/
/**
* need a handler to take care of creating a tagged user object, append that object to the taggList state variable.
* @returns
*/
// useEffect(() => {
// imageRef.current.measure((fx, fy, width, height, px, py) => {
// console.log('Component width is: ' + width);
// console.log('Component height is: ' + height);
// console.log('X offset to frame: ' + fx);
// console.log('Y offset to frame: ' + fy);
// console.log('X offset to page: ' + px);
// console.log('Y offset to page: ' + py);
// setOffset([px, py]);
// setImageDimensions([width, height]);
// });
// }, []);
const handleShare = async () => {
setLoading(true);
if (!image.filename) {
return;
}
postMoment(image.filename, image.path, caption, title, userId).then(
(data) => {
setLoading(false);
if (data) {
dispatch(loadUserMoments(userId));
dispatch(updateProfileCompletionStage(data));
navigateToProfile();
setTimeout(() => {
Alert.alert(SUCCESS_PIC_UPLOAD);
}, 500);
} else {
setTimeout(() => {
Alert.alert(ERROR_UPLOAD);
}, 500);
}
},
);
};
return (
<SearchBackground>
{loading ? <TaggLoadingIndicator fullscreen /> : <Fragment />}
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={styles.flex}>
<View style={styles.contentContainer}>
<View style={styles.buttonsContainer}>
<Button
title="Cancel"
buttonStyle={styles.button}
onPress={() => navigateToProfile()}
/>
<Button
title="Share"
titleStyle={styles.shareButtonTitle}
buttonStyle={styles.button}
onPress={handleShare}
/>
</View>
<CaptionScreenHeader style={styles.header} {...{title: title}} />
{/* this is the image we want to center our tags' initial location within */}
<Image
ref={imageRef}
style={styles.image}
source={{uri: image.path}}
resizeMode={'cover'}
/>
<MentionInput
containerStyle={styles.text}
placeholder="Write something....."
placeholderTextColor="gray"
value={caption}
onChange={setCaption}
partTypes={mentionPartTypes('blue')}
/>
{/* Draggables - Commented out for now */}
{/* <Draggable
// ivan
x={imageDimensions[0] / 2 - curStart[0] / 2 + offset[0]}
y={offset[1] + imageDimensions[1] / 2 - curStart[1] / 2}
z={999}
minX={offset[0]}
minY={offset[1]}
maxX={imageDimensions[0] + offset[0]}
maxY={imageDimensions[1] + offset[1]}
onDragStart={() => bringToFront(0)}>
<TaggDraggable
taggedUser={taggList[0]}
editingView={true}
deleteFromList={() => console.log('Hello world')}
setStart={setCurStart}
/>
</Draggable>
<Draggable
x={imageDimensions[0] / 2 - curStart[0] / 2 + offset[0]}
y={offset[1] + imageDimensions[1] / 2 - curStart[1] / 2}
z={0}
minX={offset[0]}
minY={offset[1]}
maxX={imageDimensions[0] + offset[0]}
maxY={imageDimensions[1] + offset[1]}
onDragStart={() => bringToFront(1)}>
<TaggDraggable
taggedUser={taggList[1]}
editingView={true}
deleteFromList={() => console.log('Hello world')}
setStart={setCurStart}
/>
</Draggable> */}
</View>
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
</SearchBackground>
);
};
const styles = StyleSheet.create({
contentContainer: {
paddingTop: StatusBarHeight,
justifyContent: 'flex-end',
},
buttonsContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginLeft: '5%',
marginRight: '5%',
},
button: {
backgroundColor: 'transparent',
},
shareButtonTitle: {
fontWeight: 'bold',
color: TAGG_LIGHT_BLUE_2,
},
header: {
marginVertical: 20,
},
image: {
position: 'relative',
width: SCREEN_WIDTH,
aspectRatio: 1,
marginBottom: '3%',
},
text: {
position: 'relative',
backgroundColor: 'white',
width: '100%',
paddingHorizontal: '2%',
paddingVertical: '1%',
height: 60,
},
flex: {
flex: 1,
},
});
export default CaptionScreen;
|