From 1c03e73ca473184603fbf653ddfa3aa2e2eccdef Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 19 Jan 2021 10:28:27 -0500 Subject: redesigned tagg loading indicator, added indicator to image upload --- src/components/common/TaggLoadingIndicator.tsx | 25 +++++++++++---- src/screens/profile/CaptionScreen.tsx | 43 +++++++++++++++----------- src/screens/profile/SocialMediaTaggs.tsx | 10 ++---- src/services/MomentServices.ts | 10 +----- 4 files changed, 47 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/components/common/TaggLoadingIndicator.tsx b/src/components/common/TaggLoadingIndicator.tsx index c3c44bf9..d9143bd6 100644 --- a/src/components/common/TaggLoadingIndicator.tsx +++ b/src/components/common/TaggLoadingIndicator.tsx @@ -1,11 +1,23 @@ import * as React from 'react'; -import {Image, StyleSheet, View} from 'react-native'; +import {Image, Modal, StyleSheet, View} from 'react-native'; -type TaggLoadingIndicatorProps = { - color: string; -}; -const TaggLoadingIndicator: React.FC = ({color}) => { - return ( +interface TaggLoadingIndicatorProps { + fullscreen: boolean; +} + +const TaggLoadingIndicator: React.FC = ({ + fullscreen = false, +}) => { + return fullscreen ? ( + + + + + + ) : ( = ({route, navigation}) => { user: {userId}, } = useSelector((state: RootState) => state.user); const dispatch = useDispatch(); - const [caption, setCaption] = React.useState(''); + const [caption, setCaption] = useState(''); + const [loading, setLoading] = useState(false); const handleCaptionUpdate = (caption: string) => { setCaption(caption); @@ -57,22 +61,24 @@ const CaptionScreen: React.FC = ({route, navigation}) => { }; const handleShare = async () => { - try { - const data = await postMoment( - image.filename, - image.path, - caption, - title, - userId, - ); - if (data) { - dispatch(loadUserMoments(userId)); - dispatch(updateProfileCompletionStage(data)); - navigateToProfile(); - } - } catch (err) { - console.log(err); - } + setLoading(true); + 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 ( @@ -82,6 +88,7 @@ const CaptionScreen: React.FC = ({route, navigation}) => { behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={{flex: 1}}> + {loading ? : }