diff options
author | Brian Kim <brian@tagg.id> | 2021-05-13 12:16:49 -0700 |
---|---|---|
committer | Brian Kim <brian@tagg.id> | 2021-05-13 12:16:49 -0700 |
commit | e884ad25b4f2358406eee8a2766890291538a518 (patch) | |
tree | eb6f0deeb66f3ebcd35ebeda6618c31f71933954 | |
parent | c9a4810a873c6cccb94a1c7761486343258527ea (diff) |
Cleaned up code somewhat
-rw-r--r-- | src/components/profile/Cover.tsx | 36 | ||||
-rw-r--r-- | src/components/profile/TaggAvatar.tsx | 2 | ||||
-rw-r--r-- | src/utils/users.ts | 47 |
3 files changed, 44 insertions, 41 deletions
diff --git a/src/components/profile/Cover.tsx b/src/components/profile/Cover.tsx index 82231417..5d5b4234 100644 --- a/src/components/profile/Cover.tsx +++ b/src/components/profile/Cover.tsx @@ -13,7 +13,7 @@ import GreyPurplePlus from '../../assets/icons/grey-purple-plus.svg'; import {useDispatch, useSelector} from 'react-redux'; import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; import {RootState} from '../../store/rootreducer'; -import {patchProfile, validateImageLink} from '../../utils'; +import {normalize, patchProfile, validateImageLink} from '../../utils'; interface CoverProps { userXId: string | undefined; @@ -44,7 +44,7 @@ const Cover: React.FC<CoverProps> = ({userXId, screenType}) => { const handleNewImage = async () => { setLoading(true); - const result = await patchProfile('Select Header Picture', user.userId); + const result = await patchProfile('header', user.userId); setLoading(true); if (result) { setNeedsUpdate(true); @@ -62,22 +62,20 @@ const Cover: React.FC<CoverProps> = ({userXId, screenType}) => { if (!validImage && userXId === undefined && !loading) { return ( - <> - <View style={[styles.container]}> - <ImageBackground - style={styles.image} - defaultSource={require('../../assets/images/cover-placeholder.png')} - source={{uri: cover, cache: 'reload'}}> - <TouchableOpacity - accessible={true} - accessibilityLabel="ADD HEADER PICTURE" - onPress={() => handleNewImage()}> - <GreyPurplePlus style={styles.plus} /> - <Text style={styles.text}>Add Picture</Text> - </TouchableOpacity> - </ImageBackground> - </View> - </> + <View style={[styles.container]}> + <ImageBackground + style={styles.image} + defaultSource={require('../../assets/images/cover-placeholder.png')} + source={{uri: cover, cache: 'reload'}}> + <TouchableOpacity + accessible={true} + accessibilityLabel="ADD HEADER PICTURE" + onPress={() => handleNewImage()}> + <GreyPurplePlus style={styles.plus} /> + <Text style={styles.text}>Add Picture</Text> + </TouchableOpacity> + </ImageBackground> + </View> ); } else { return ( @@ -108,7 +106,7 @@ const styles = StyleSheet.create({ text: { color: 'white', position: 'absolute', - fontSize: 18, + fontSize: normalize(16), top: 80, right: 20, }, diff --git a/src/components/profile/TaggAvatar.tsx b/src/components/profile/TaggAvatar.tsx index 1f6bbba6..304b9e3a 100644 --- a/src/components/profile/TaggAvatar.tsx +++ b/src/components/profile/TaggAvatar.tsx @@ -46,7 +46,7 @@ const TaggAvatar: React.FC<TaggAvatarProps> = ({ const handleNewImage = async () => { setLoading(true); - const result = await patchProfile('Select Profile Picture', user.userId); + const result = await patchProfile('profile', user.userId); if (result) { setNeedsUpdate(true); } else { diff --git a/src/utils/users.ts b/src/utils/users.ts index bc81bbc6..430c843f 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -244,10 +244,19 @@ export const navigateToProfile = async ( }); }; -export const patchProfile = async (title: string, userId: string) => { +export const patchProfile = async ( + title: 'profile' | 'header', + userId: string, +) => { let imageSettings = {}; + let screenTitle: string; + let requestTitle: string; + let fileName: string; switch (title) { - case 'Select Header Picture': + case 'header': + screenTitle = 'Select Header Picture'; + requestTitle = 'largeProfilePicture'; + fileName = 'large_profile_pic.jpg'; imageSettings = { smartAlbums: [ 'Favorites', @@ -259,11 +268,14 @@ export const patchProfile = async (title: string, userId: string) => { width: 580, height: 580, cropping: true, - cropperToolbarTitle: title, + cropperToolbarTitle: screenTitle, mediaType: 'photo', }; break; - case 'Select Profile Picture': + case 'profile': + screenTitle = 'Select Profile Picture'; + requestTitle = 'smallProfilePicture'; + fileName = 'small_profile_pic.jpg'; imageSettings = { smartAlbums: [ 'Favorites', @@ -275,33 +287,26 @@ export const patchProfile = async (title: string, userId: string) => { width: 580, height: 580, cropping: true, - cropperToolbarTitle: title, + cropperToolbarTitle: screenTitle, mediaType: 'photo', cropperCircleOverlay: true, }; break; + default: + screenTitle = ''; + requestTitle = ''; + fileName = ''; } return await ImagePicker.openPicker(imageSettings) .then((picture) => { if ('path' in picture) { const request = new FormData(); - switch (title) { - case 'Select Header Picture': - request.append('largeProfilePicture', { - uri: picture.path, - name: 'large_profile_pic.jpg', - type: 'image/jpg', - }); - break; - case 'Select Profile Picture': - request.append('smallProfilePicture', { - uri: picture.path, - name: 'small_profile_pic.jpg', - type: 'image/jpg', - }); - break; - } + request.append(requestTitle, { + uri: picture.path, + name: fileName, + type: 'image/jpg', + }); return patchEditProfile(request, userId) .then((_) => { |