From e884ad25b4f2358406eee8a2766890291538a518 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Thu, 13 May 2021 12:16:49 -0700 Subject: Cleaned up code somewhat --- src/components/profile/Cover.tsx | 36 +++++++++++++-------------- src/components/profile/TaggAvatar.tsx | 2 +- src/utils/users.ts | 47 +++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 41 deletions(-) (limited to 'src') 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 = ({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 = ({userXId, screenType}) => { if (!validImage && userXId === undefined && !loading) { return ( - <> - - - handleNewImage()}> - - Add Picture - - - - + + + handleNewImage()}> + + Add Picture + + + ); } 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 = ({ 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((_) => { -- cgit v1.2.3-70-g09d2