From 205475150e32a309f25f878b4c58a4eba890cb01 Mon Sep 17 00:00:00 2001
From: Ivan Chen <ivan@tagg.id>
Date: Wed, 23 Jun 2021 15:36:07 -0400
Subject: Cleanup code, Add support for video

---
 src/screens/profile/CaptionScreen.tsx | 43 +++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 14 deletions(-)

(limited to 'src/screens/profile/CaptionScreen.tsx')

diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index bb02494d..48724620 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -51,7 +51,7 @@ interface CaptionScreenProps {
 }
 
 const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
-  const {title, media, screenType, selectedTags, moment} = route.params;
+  const {title, screenType, selectedTags, moment} = route.params;
   const {
     user: {userId},
   } = useSelector((state: RootState) => state.user);
@@ -62,6 +62,17 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
     selectedTags ? selectedTags : [],
   );
   const [taggedList, setTaggedList] = useState<string>('');
+  const mediaFilename = moment ? undefined : route.params.media!.filename;
+  const mediaUri = moment ? moment.moment_url : route.params.media!.uri;
+  // TODO: change this once moment refactor is done
+  const isMediaAVideo = moment
+    ? !(
+        moment.moment_url.endsWith('.jpg') ||
+        moment.moment_url.endsWith('.JPG') ||
+        moment.moment_url.endsWith('.png') ||
+        moment.moment_url.endsWith('.PNG')
+      )
+    : route.params.media?.type === 'video';
 
   useEffect(() => {
     setTags(selectedTags ? selectedTags : []);
@@ -120,12 +131,12 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
 
   const handleShare = async () => {
     setLoading(true);
-    if (!media || !title) {
+    if (moment || !mediaFilename || !title) {
       return;
     }
     const momentResponse = await postMoment(
-      media.filename,
-      media.uri,
+      mediaFilename,
+      mediaUri,
       caption,
       title,
       userId,
@@ -191,14 +202,18 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
             </View>
             <CaptionScreenHeader
               style={styles.header}
-              {...{title: moment ? moment.moment_category : title}}
-            />
-            {/* this is the image we want to center our tags' initial location within */}
-            <Image
-              style={styles.image}
-              source={{uri: moment ? moment.moment_url : image?.path}}
-              resizeMode={'cover'}
+              {...{title: moment ? moment.moment_category : title ?? ''}}
             />
+            {isMediaAVideo ? (
+              // <Video uri={mediaUri} style={styles.media} />
+              <></>
+            ) : (
+              <Image
+                style={styles.media}
+                source={{uri: mediaUri}}
+                resizeMode={'cover'}
+              />
+            )}
             <MentionInput
               containerStyle={styles.text}
               placeholder="Write something....."
@@ -212,8 +227,8 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
                 navigation.navigate('TagFriendsScreen', {
                   imagePath: moment
                     ? moment.moment_url
-                    : image
-                    ? image.path
+                    : media
+                    ? media.uri
                     : '',
                   selectedTags: tags,
                 })
@@ -257,7 +272,7 @@ const styles = StyleSheet.create({
   header: {
     marginVertical: 20,
   },
-  image: {
+  media: {
     position: 'relative',
     width: SCREEN_WIDTH,
     aspectRatio: 1,
-- 
cgit v1.2.3-70-g09d2

