aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile
diff options
context:
space:
mode:
authorShravya Ramesh <37447613+shravyaramesh@users.noreply.github.com>2021-07-23 16:01:16 -0700
committerGitHub <noreply@github.com>2021-07-23 16:01:16 -0700
commit93b0bdb6d5d3070ece012626f9d9d6634f0eb0d8 (patch)
treede1aab12445184023db6b7f1e5dce94e8416d233 /src/screens/profile
parent6fcfb36b37dd51d3e9d5baf025b896cc6f6045ee (diff)
parent2f64db843b80229d08f8f0ae7e1d80b24ac38c12 (diff)
Merge branch 'master' into tma936-pause-video
Diffstat (limited to 'src/screens/profile')
-rw-r--r--src/screens/profile/CaptionScreen.tsx55
-rw-r--r--src/screens/profile/IndividualMoment.tsx37
-rw-r--r--src/screens/profile/ProfileScreen.tsx2
3 files changed, 61 insertions, 33 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index 7f77bdca..6ba1791c 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -34,14 +34,9 @@ import {
} from '../../constants/strings';
import * as RootNavigation from '../../RootNavigation';
import {MainStackParams} from '../../routes';
+import {patchMoment, postMoment, postMomentTags} from '../../services';
import {
- handlePresignedURL,
- handleVideoUpload,
- patchMoment,
- postMoment,
- postMomentTags,
-} from '../../services';
-import {
+ handleVideoMomentUpload,
loadUserMoments,
updateProfileCompletionStage,
} from '../../store/actions';
@@ -76,6 +71,8 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const [tags, setTags] = useState<MomentTagType[]>([]);
const [taggedUsersText, setTaggedUsersText] = useState('');
const [momentCategory, setMomentCategory] = useState<string | undefined>();
+ // only used for upload purposes, undefined for editing is fine
+ const videoDuration = moment ? undefined : route.params.media!.videoDuration;
const mediaUri = moment ? moment.moment_url : route.params.media!.uri;
// TODO: change this once moment refactor is done
const isMediaAVideo = moment
@@ -133,11 +130,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
navigation.popToTop();
RootNavigation.navigate('ProfileTab');
setTimeout(() => {
- if (isMediaAVideo) {
- Alert.alert(
- 'Beautiful, the Moment was uploaded successfully! Check back in a bit and refresh to see it!',
- );
- } else {
+ if (!isMediaAVideo) {
Alert.alert(SUCCESS_PIC_UPLOAD);
}
}, 500);
@@ -166,20 +159,20 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
return;
}
let profileCompletionStage;
- let momentId;
// separate upload logic for image/video
if (isMediaAVideo) {
- const presignedURLResponse = await handlePresignedURL(momentCategory);
- if (!presignedURLResponse) {
- handleFailed();
- return;
- }
- momentId = presignedURLResponse.moment_id;
- const fileHash = presignedURLResponse.response_url.fields.key;
- if (fileHash !== null && fileHash !== '' && fileHash !== undefined) {
- await handleVideoUpload(mediaUri, presignedURLResponse);
+ if (videoDuration) {
+ dispatch(
+ handleVideoMomentUpload(
+ mediaUri,
+ videoDuration,
+ momentCategory,
+ formattedTags(),
+ ),
+ );
} else {
handleFailed();
+ return;
}
} else {
const momentResponse = await postMoment(
@@ -193,13 +186,16 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
return;
}
profileCompletionStage = momentResponse.profile_completion_stage;
- momentId = momentResponse.moment_id;
- }
- if (momentId) {
- const momentTagResponse = await postMomentTags(momentId, formattedTags());
- if (!momentTagResponse) {
- handleFailed();
- return;
+ const momentId = momentResponse.moment_id;
+ if (momentId) {
+ const momentTagResponse = await postMomentTags(
+ momentId,
+ formattedTags(),
+ );
+ if (!momentTagResponse) {
+ handleFailed();
+ return;
+ }
}
}
if (!isMediaAVideo) {
@@ -325,6 +321,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
media: {
uri: mediaUri,
isVideo: isMediaAVideo,
+ videoDuration,
},
selectedTags: tags,
})
diff --git a/src/screens/profile/IndividualMoment.tsx b/src/screens/profile/IndividualMoment.tsx
index 1b0c7c2b..0cfbce28 100644
--- a/src/screens/profile/IndividualMoment.tsx
+++ b/src/screens/profile/IndividualMoment.tsx
@@ -5,6 +5,7 @@ import {FlatList, Keyboard, ViewToken} from 'react-native';
import {useSelector} from 'react-redux';
import {MomentPost, TabsGradient} from '../../components';
import {MainStackParams} from '../../routes';
+import {increaseMomentViewCount} from '../../services';
import {RootState} from '../../store/rootreducer';
import {MomentPostType} from '../../types';
import {SCREEN_HEIGHT} from '../../utils';
@@ -38,9 +39,16 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({route}) => {
userXId ? state.userX[screenType][userXId] : state.moments,
);
const scrollRef = useRef<FlatList<MomentPostType>>(null);
- const momentData = moments.filter(
- (m) => m.moment_category === moment_category,
- );
+ const [momentData, setMomentData] = useState<MomentPostType[]>([]);
+
+ useEffect(() => {
+ const extractedMoments = moments.filter(
+ (m) => m.moment_category === moment_category,
+ );
+ setMomentData(extractedMoments);
+ console.log('momentData: ', momentData);
+ }, [moments]);
+
const initialIndex = momentData.findIndex((m) => m.moment_id === moment_id);
const [keyboardVisible, setKeyboardVisible] = useState(false);
const [currentVisibleMomentId, setCurrentVisibleMomentId] = useState<
@@ -75,6 +83,28 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({route}) => {
};
}, []);
+ const updateMomentViewCount = () => {
+ if (currentVisibleMomentId) {
+ increaseMomentViewCount(currentVisibleMomentId)
+ .then((updatedViewCount) => {
+ const updatedMomentData = momentData.map((x) => {
+ return x.moment_id === currentVisibleMomentId
+ ? {...x, view_count: updatedViewCount}
+ : x;
+ });
+ setMomentData(updatedMomentData);
+ })
+ .catch(() => console.log('Error updating view count!'));
+ }
+ };
+
+ /*
+ * Increments view count when user swipes up or down on Flatlist
+ */
+ useEffect(() => {
+ updateMomentViewCount();
+ }, [currentVisibleMomentId]);
+
return (
<MomentContext.Provider
value={{
@@ -90,6 +120,7 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({route}) => {
moment={item}
userXId={userXId}
screenType={screenType}
+ updateMomentViewCount={updateMomentViewCount}
/>
)}
keyboardShouldPersistTaps={'handled'}
diff --git a/src/screens/profile/ProfileScreen.tsx b/src/screens/profile/ProfileScreen.tsx
index 3dd142e1..09b70cd3 100644
--- a/src/screens/profile/ProfileScreen.tsx
+++ b/src/screens/profile/ProfileScreen.tsx
@@ -1,7 +1,7 @@
+import {RouteProp} from '@react-navigation/native';
import React, {useEffect} from 'react';
import {StatusBar} from 'react-native';
import {Content, TabsGradient} from '../../components';
-import {RouteProp} from '@react-navigation/native';
import {MainStackParams} from '../../routes/';
import {visitedUserProfile} from '../../services';