diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/users.ts | 47 |
1 files changed, 26 insertions, 21 deletions
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((_) => { |
