From af2136ff699ac4556732da4e262add82c15b2b5c Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 15:39:42 -0400 Subject: code cleanup and added cache: reload --- src/components/profile/Avatar.tsx | 8 +-- src/components/profile/Cover.tsx | 8 +-- src/screens/profile/EditProfile.tsx | 58 +++++++++++----------- .../SuggestedPeopleUploadPictureScreen.tsx | 2 +- 4 files changed, 39 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/components/profile/Avatar.tsx b/src/components/profile/Avatar.tsx index 5d677983..e57a56a3 100644 --- a/src/components/profile/Avatar.tsx +++ b/src/components/profile/Avatar.tsx @@ -12,15 +12,15 @@ interface AvatarProps { screenType: ScreenType; } const Avatar: React.FC = ({style, screenType, userXId}) => { - const {avatar} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + const {avatar} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); return ( ); }; diff --git a/src/components/profile/Cover.tsx b/src/components/profile/Cover.tsx index b7502cff..ee804ff3 100644 --- a/src/components/profile/Cover.tsx +++ b/src/components/profile/Cover.tsx @@ -10,16 +10,16 @@ interface CoverProps { screenType: ScreenType; } const Cover: React.FC = ({userXId, screenType}) => { - const {cover} = userXId - ? useSelector((state: RootState) => state.userX[screenType][userXId]) - : useSelector((state: RootState) => state.user); + const {cover} = useSelector((state: RootState) => + userXId ? state.userX[screenType][userXId] : state.user, + ); return ( ); diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 8afaeb6d..ac992142 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -1,52 +1,48 @@ -import React, {Fragment, useCallback, useEffect, useState} from 'react'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; +import React, {Fragment, useCallback, useEffect, useState} from 'react'; import { - Text, + Alert, + Image, + Keyboard, + KeyboardAvoidingView, + Platform, + SafeAreaView, StatusBar, StyleSheet, - Image, + Text, TouchableOpacity, - Alert, View, - SafeAreaView, - KeyboardAvoidingView, - Platform, - Keyboard, } from 'react-native'; import {Button} from 'react-native-elements'; +import ImagePicker from 'react-native-image-crop-picker'; +import Animated from 'react-native-reanimated'; +import {useDispatch, useSelector} from 'react-redux'; import { Background, + SocialIcon, + TabsGradient, TaggBigInput, - TaggInput, TaggDropDown, - TabsGradient, - SocialIcon, + TaggInput, } from '../../components'; -import ImagePicker from 'react-native-image-crop-picker'; +import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; import { - EDIT_PROFILE_ENDPOINT, - websiteRegex, bioRegex, - genderRegex, CLASS_YEAR_LIST, + genderRegex, + websiteRegex, } from '../../constants'; -import AsyncStorage from '@react-native-community/async-storage'; -import {MainStackParams} from '../../routes'; -import Animated from 'react-native-reanimated'; -import {HeaderHeight, SCREEN_HEIGHT} from '../../utils'; -import {RootState} from '../../store/rootReducer'; -import {useDispatch, useSelector} from 'react-redux'; -import {loadUserData} from '../../store/actions'; -import {BackgroundGradientType, ScreenType} from '../../types'; import { - ERROR_DOUBLE_CHECK_CONNECTION, - ERROR_SOMETHING_WENT_WRONG_REFRESH, ERROR_UPLOAD_LARGE_PROFILE_PIC, ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; -import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; +import {MainStackParams} from '../../routes'; import {patchEditProfile} from '../../services'; +import {loadUserData} from '../../store/actions'; +import {RootState} from '../../store/rootReducer'; +import {BackgroundGradientType, ScreenType} from '../../types'; +import {HeaderHeight, SCREEN_HEIGHT} from '../../utils'; type EditProfileNavigationProp = StackNavigationProp< MainStackParams, @@ -120,7 +116,10 @@ const EditProfile: React.FC = ({route, navigation}) => { onPress={goToGalleryLargePic} style={styles.largeProfileUploader}> {form.largePic ? ( - + ) : ( ADD HEADER IMAGE )} @@ -137,7 +136,10 @@ const EditProfile: React.FC = ({route, navigation}) => { onPress={goToGallerySmallPic} style={styles.smallProfileUploader}> {form.smallPic ? ( - + ) : ( ADD PROFILE PICTURE )} diff --git a/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx b/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx index e1bcb477..b072a9b5 100644 --- a/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx +++ b/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx @@ -52,7 +52,7 @@ const SuggestedPeopleUploadPictureScreen: React.FC state.user); useEffect(() => { -- cgit v1.2.3-70-g09d2 From 1bed2a96e83e06613c8255d1264b10d7afee6720 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 29 Mar 2021 18:52:40 -0400 Subject: reset url in state after editing profile --- src/screens/profile/EditProfile.tsx | 3 ++- src/store/actions/user.ts | 13 +++++++++++++ src/store/reducers/userReducer.ts | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index ac992142..de950923 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -39,7 +39,7 @@ import { } from '../../constants/strings'; import {MainStackParams} from '../../routes'; import {patchEditProfile} from '../../services'; -import {loadUserData} from '../../store/actions'; +import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {BackgroundGradientType, ScreenType} from '../../types'; import {HeaderHeight, SCREEN_HEIGHT} from '../../utils'; @@ -74,6 +74,7 @@ const EditProfile: React.FC = ({route, navigation}) => { useEffect(() => { if (needsUpdate) { + dispatch(resetHeaderAndProfileImage()); dispatch(loadUserData({userId, username})); } }, [dispatch, needsUpdate, userId, username]); diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 46f96d9a..10132dd9 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -7,6 +7,7 @@ import { import {UserType} from '../../types/types'; import {getTokenOrLogout} from '../../utils'; import { + clearHeaderAndProfileImages, profileCompletionStageUpdated, setIsOnboardedUser, setNewNotificationReceived, @@ -54,6 +55,18 @@ export const loadUserData = ( } }; +export const resetHeaderAndProfileImage = (): ThunkAction< + Promise, + RootState, + unknown, + Action +> => async (dispatch) => { + await dispatch({ + type: clearHeaderAndProfileImages.type, + payload: {}, + }); +}; + /** * To update editable socials * @param social social to be updated diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index 587aa374..9ff9ba01 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -70,6 +70,11 @@ const userDataSlice = createSlice({ setSuggestedPeopleImage: (state, action) => { state.suggestedPeopleImage = action.payload.suggestedPeopleImage; }, + + clearHeaderAndProfileImages: (state) => { + state.avatar = ''; + state.cover = ''; + }, }, }); @@ -84,5 +89,6 @@ export const { setNewNotificationReceived, setReplyPosted, setSuggestedPeopleImage, + clearHeaderAndProfileImages, } = userDataSlice.actions; export const userDataReducer = userDataSlice.reducer; -- cgit v1.2.3-70-g09d2