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 /src/utils/users.ts | |
parent | c9a4810a873c6cccb94a1c7761486343258527ea (diff) |
Cleaned up code somewhat
Diffstat (limited to 'src/utils/users.ts')
-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((_) => { |