From 0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Fri, 4 Dec 2020 08:50:24 -0800 Subject: [TMA - 398 AND TMA-430] Replace Providers with Redux Store (#125) * First * WIP * Thunk * Some more comments * sc * recent searches and follounfollow * Edit profile dummy * Block / unblock and some cleanup * Replace auth provider * Sc * Delete AP after rebase * Discover users * Cleanup * More cleanup * Replace profile provider * Fixed build failure * Fixed a bug reported * Prevent app crash when backend server is down --- src/screens/profile/CaptionScreen.tsx | 26 ++++--- src/screens/profile/EditProfile.tsx | 13 ++-- src/screens/profile/FollowersListScreen.tsx | 21 +++++- src/screens/profile/IndividualMoment.tsx | 25 +++++-- src/screens/profile/MomentCommentsScreen.tsx | 15 ++-- src/screens/profile/ProfileScreen.tsx | 74 ++++++++++---------- src/screens/profile/SocialMediaTaggs.tsx | 100 +++++++++++++++++---------- 7 files changed, 171 insertions(+), 103 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 08dd8e5b..e9eed668 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -18,7 +18,9 @@ import {ProfileStackParams} from 'src/routes'; import {StackNavigationProp} from '@react-navigation/stack'; import {CaptionScreenHeader} from '../../components/'; import {MOMENTS_ENDPOINT} from '../../constants'; -import {AuthContext} from '../../routes/authentication'; +import {useDispatch, useSelector} from 'react-redux'; +import {loadUserMoments} from '../../store/actions'; +import {RootState} from '../../store/rootReducer'; /** * Upload Screen to allow users to upload posts to Tagg @@ -34,11 +36,11 @@ interface CaptionScreenProps { } const CaptionScreen: React.FC = ({route, navigation}) => { - const {title, image} = route.params; + const {title, image, screenType} = route.params; const { user: {userId}, - updateMoments, - } = React.useContext(AuthContext); + } = useSelector((state: RootState) => state.user); + const dispatch = useDispatch(); const [caption, setCaption] = React.useState(''); const handleCaptionUpdate = (caption: string) => { @@ -54,6 +56,14 @@ const CaptionScreen: React.FC = ({route, navigation}) => { return true; }; + const navigateToProfile = () => { + //Since the logged In User is navigating to own profile, useXId is not required + navigation.navigate('Profile', { + screenType, + userXId: undefined, + }); + }; + const handleShare = async () => { try { const request = new FormData(); @@ -86,8 +96,8 @@ const CaptionScreen: React.FC = ({route, navigation}) => { let data = await response.json(); if (statusCode === 200 && checkImageUploadStatus(data)) { Alert.alert('The picture was uploaded successfully!'); - updateMoments(true); - navigation.navigate('Profile', {isProfileView: false}); + dispatch(loadUserMoments(userId)); + navigateToProfile(); } else { Alert.alert('An error occured while uploading. Please try again!'); } @@ -107,9 +117,7 @@ const CaptionScreen: React.FC = ({route, navigation}) => {